com-tecnick-tcpdf
[ class tree: com-tecnick-tcpdf ] [ index: com-tecnick-tcpdf ] [ all elements ]

Source for file tcpdf.php

Documentation is available at tcpdf.php

  1. <?php
  2. //============================================================+
  3. // File name   : tcpdf.php
  4. // Begin       : 2002-08-03
  5. // Last Update : 2009-02-18
  6. // Author      : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
  7. // Version     : 4.5.015
  8. // License     : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. //     ----------------------------------------------------------------------------
  10. //  Copyright (C) 2002-2009  Nicola Asuni - Tecnick.com S.r.l.
  11. //     
  12. //     This program is free software: you can redistribute it and/or modify
  13. //     it under the terms of the GNU Lesser General Public License as published by
  14. //     the Free Software Foundation, either version 2.1 of the License, or
  15. //     (at your option) any later version.
  16. //     
  17. //     This program is distributed in the hope that it will be useful,
  18. //     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. //     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. //     GNU Lesser General Public License for more details.
  21. //     
  22. //     You should have received a copy of the GNU Lesser General Public License
  23. //     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24. //     
  25. //     See LICENSE.TXT file for more information.
  26. //  ----------------------------------------------------------------------------
  27. //
  28. // Description : This is a PHP class for generating PDF documents without 
  29. //               requiring external extensions.
  30. //
  31. // NOTE:
  32. // This class was originally derived in 2002 from the Public 
  33. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org), 
  34. // but now is almost entirely rewritten.
  35. //
  36. // Main features:
  37. //  * no external libraries are required for the basic functions;
  38. //     * supports all ISO page formats;
  39. //     * supports UTF-8 Unicode and Right-To-Left languages;
  40. //     * supports document encryption;
  41. //     * includes methods to publish some XHTML code;
  42. //     * includes graphic (geometric) and transformation methods;
  43. //     * includes bookmarks;
  44. //     * includes Javascript and forms support;
  45. //     * includes a method to print various barcode formats;
  46. //     * supports TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  47. //     * supports custom page formats, margins and units of measure;
  48. //     * includes methods for page header and footer management;
  49. //     * supports automatic page break;
  50. //     * supports automatic page numbering and page groups;
  51. //     * supports automatic line break and text justification;
  52. //     * supports JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;
  53. //     * supports stroke and clipping mode for text;
  54. //     * supports clipping masks;
  55. //     * supports Grayscale, RGB, CMYK, Spot colors and transparency;
  56. //     * supports links and annotations;
  57. //     * supports page compression (requires zlib extension);
  58. //     * supports PDF user's rights.
  59. //
  60. // -----------------------------------------------------------
  61. // THANKS TO:
  62. // 
  63. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  64. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  65. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  66. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  67. // dullus for text Justification.
  68. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  69. // Patrick Benny for text stretch suggestion on Cell().
  70. // Johannes Güntert for JavaScript support.
  71. // Denis Van Nuffelen for Dynamic Form.
  72. // Jacek Czekaj for multibyte justification
  73. // Anthony Ferrara for the reintroduction of legacy image methods.
  74. // Sourceforge user 1707880 (hucste) for line-trough mode.
  75. // Larry Stanbery for page groups.
  76. // Martin Hall-May for transparency.
  77. // Aaron C. Spike for Polycurve method.
  78. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  79. // Moritz Wagner and Andreas Wurmser for graphic functions.
  80. // Andrew Whitehead for core fonts support.
  81. // Esteban Joël Marín for OpenType font conversion.
  82. // Teus Hagen for several suggestions and fixes.
  83. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  84. // Kosmas Papachristos for some CSS improvements.
  85. // Marcel Partap for some fixes.
  86. // Won Kyu Park for several suggestions, fixes and patches.
  87. // Anyone that has reported a bug or sent a suggestion.
  88. //============================================================+
  89.  
  90. /**
  91.  * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  92.  * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  93.  * <h3>TCPDF main features are:</h3>
  94.  * <ul>
  95.  * <li>no external libraries are required for the basic functions;</li>
  96.  * <li>supports all ISO page formats;</li>
  97.  * <li>supports UTF-8 Unicode and Right-To-Left languages;</li>
  98.  * <li>supports document encryption;</li>
  99.  * <li>includes methods to publish some XHTML code;</li>
  100.  * <li>includes graphic (geometric) and transformation methods;</li>
  101.  * <li>includes bookmarks;</li>
  102.  * <li>includes Javascript and forms support;</li>
  103.  * <li>includes a method to print various barcode formats;</li>
  104.  * <li>supports TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  105.  * <li>supports custom page formats, margins and units of measure;</li>
  106.  * <li>includes methods for page header and footer management;</li>
  107.  * <li>supports automatic page break;</li>
  108.  * <li>supports automatic page numbering and page groups;</li>
  109.  * <li>supports automatic line break and text justification;
  110.  * <li>supports JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;</li>
  111.  * <li>supports stroke and clipping mode for text;</li>
  112.  * <li>supports clipping masks;</li>
  113.  * <li>supports Grayscale, RGB and CMYK colors and transparency;</li>
  114.  * <li>supports links and annotations;</li>
  115.  * <li>supports page compression (requires zlib extension);</li>
  116.  * <li>supports PDF user's rights.</li>
  117.  * </ul>
  118.  * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  119.  * @package com.tecnick.tcpdf
  120.  * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  121.  * @author Nicola Asuni
  122.  * @copyright 2002-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  123.  * @link http://www.tcpdf.org
  124.  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  125.  * @version 4.5.015
  126.  */
  127.  
  128. /**
  129.  * main configuration file
  130.  */
  131. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  132.  
  133. // includes some support files
  134.  
  135. /**
  136.  * unicode data
  137.  */
  138. require_once(dirname(__FILE__).'/unicode_data.php');
  139.  
  140. /**
  141.  * html colors table
  142.  */
  143. require_once(dirname(__FILE__).'/htmlcolors.php');
  144.  
  145. if (!class_exists('TCPDF'false)) {
  146.     /**
  147.      * define default PDF document producer
  148.      */ 
  149.     define('PDF_PRODUCER''TCPDF 4.5.015 (http://www.tcpdf.org)');
  150.     
  151.     /**
  152.     * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  153.     * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  154.     * @name TCPDF
  155.     * @package com.tecnick.tcpdf
  156.     * @version 4.5.015
  157.     * @author Nicola Asuni - info@tecnick.com
  158.     * @link http://www.tcpdf.org
  159.     * @license http://www.gnu.org/copyleft/lesser.html LGPL
  160.     */
  161.     class TCPDF {
  162.         
  163.         // protected or Protected properties
  164.  
  165.         /**
  166.         * @var current page number
  167.         * @access protected
  168.         */
  169.         protected $page;
  170.         
  171.         /**
  172.         * @var current object number
  173.         * @access protected
  174.         */
  175.         protected $n;
  176.  
  177.         /**
  178.         * @var array of object offsets
  179.         * @access protected
  180.         */
  181.         protected $offsets;
  182.  
  183.         /**
  184.         * @var buffer holding in-memory PDF
  185.         * @access protected
  186.         */
  187.         protected $buffer;
  188.  
  189.         /**
  190.         * @var array containing pages
  191.         * @access protected
  192.         */
  193.         protected $pages = array();
  194.  
  195.         /**
  196.         * @var current document state
  197.         * @access protected
  198.         */
  199.         protected $state;
  200.  
  201.         /**
  202.         * @var compression flag
  203.         * @access protected
  204.         */
  205.         protected $compress;
  206.         
  207.         /**
  208.         * @var current page orientation (P = Portrait, L = Landscape)
  209.         * @access protected
  210.         */
  211.         protected $CurOrientation;
  212.  
  213.         /**
  214.         * @var array that stores page dimensions and graphic status.<ul><li>$this->pagedim[$this->page]['w'] => page_width_in_points</li><li>$this->pagedim[$this->page]['h'] => height in points</li><li>$this->pagedim[$this->page]['wk'] => page_width_in_points</li><li>$this->pagedim[$this->page]['hk'] => height</li><li>$this->pagedim[$this->page]['tm'] => top_margin</li><li>$this->pagedim[$this->page]['bm'] => bottom_margin</li><li>$this->pagedim[$this->page]['lm'] => left_margin</li><li>$this->pagedim[$this->page]['rm'] => right_margin</li><li>$this->pagedim[$this->page]['pb'] => auto_page_break</li><li>$this->pagedim[$this->page]['or'] => page_orientation</li><li>$this->pagedim[$this->page]['olm'] => original_left_margin</li><li>$this->pagedim[$this->page]['orm'] => original_right_margin</li></ul>
  215.         * @access protected
  216.         */
  217.         protected $pagedim = array();
  218.  
  219.         /**
  220.         * @var scale factor (number of points in user unit)
  221.         * @access protected
  222.         */
  223.         protected $k;
  224.  
  225.         /**
  226.         * @var width of page format in points
  227.         * @access protected
  228.         */
  229.         protected $fwPt;
  230.  
  231.         /**
  232.         * @var height of page format in points
  233.         * @access protected
  234.         */
  235.         protected $fhPt;
  236.  
  237.         /**
  238.         * @var current width of page in points
  239.         * @access protected
  240.         */
  241.         protected $wPt;
  242.  
  243.         /**
  244.         * @var current height of page in points
  245.         * @access protected
  246.         */
  247.         protected $hPt;
  248.  
  249.         /**
  250.         * @var current width of page in user unit
  251.         * @access protected
  252.         */
  253.         protected $w;
  254.  
  255.         /**
  256.         * @var current height of page in user unit
  257.         * @access protected
  258.         */
  259.         protected $h;
  260.  
  261.         /**
  262.         * @var left margin
  263.         * @access protected
  264.         */
  265.         protected $lMargin;
  266.  
  267.         /**
  268.         * @var top margin
  269.         * @access protected
  270.         */
  271.         protected $tMargin;
  272.  
  273.         /**
  274.         * @var right margin
  275.         * @access protected
  276.         */
  277.         protected $rMargin;
  278.  
  279.         /**
  280.         * @var page break margin
  281.         * @access protected
  282.         */
  283.         protected $bMargin;
  284.  
  285.         /**
  286.         * @var cell internal padding
  287.         * @access protected
  288.         */
  289.         //protected 
  290.         public $cMargin;
  291.         
  292.         /**
  293.         * @var cell internal padding (previous value)
  294.         * @access protected
  295.         */
  296.         protected $oldcMargin;
  297.  
  298.         /**
  299.         * @var current horizontal position in user unit for cell positioning
  300.         * @access protected
  301.         */
  302.         protected $x;
  303.  
  304.         /**
  305.         * @var current vertical position in user unit for cell positioning
  306.         * @access protected
  307.         */
  308.         protected $y;
  309.  
  310.         /**
  311.         * @var height of last cell printed
  312.         * @access protected
  313.         */
  314.         protected $lasth;
  315.  
  316.         /**
  317.         * @var line width in user unit
  318.         * @access protected
  319.         */
  320.         protected $LineWidth;
  321.  
  322.         /**
  323.         * @var array of standard font names
  324.         * @access protected
  325.         */
  326.         protected $CoreFonts;
  327.  
  328.         /**
  329.         * @var array of used fonts
  330.         * @access protected
  331.         */
  332.         protected $fonts = array();
  333.  
  334.         /**
  335.         * @var array of font files
  336.         * @access protected
  337.         */
  338.         protected $FontFiles = array();
  339.  
  340.         /**
  341.         * @var array of encoding differences
  342.         * @access protected
  343.         */
  344.         protected $diffs = array();
  345.  
  346.         /**
  347.         * @var array of used images
  348.         * @access protected
  349.         */
  350.         protected $images = array();
  351.  
  352.         /**
  353.         * @var array of Annotations in pages
  354.         * @access protected
  355.         */
  356.         protected $PageAnnots = array();
  357.  
  358.         /**
  359.         * @var array of internal links
  360.         * @access protected
  361.         */
  362.         protected $links = array();
  363.  
  364.         /**
  365.         * @var current font family
  366.         * @access protected
  367.         */
  368.         protected $FontFamily;
  369.  
  370.         /**
  371.         * @var current font style
  372.         * @access protected
  373.         */
  374.         protected $FontStyle;
  375.         
  376.         /**
  377.         * @var current font ascent (distance between font top and baseline)
  378.         * @access protected
  379.         * @since 2.8.000 (2007-03-29)
  380.         */
  381.         protected $FontAscent;
  382.         
  383.         /**
  384.         * @var current font descent (distance between font bottom and baseline)
  385.         * @access protected
  386.         * @since 2.8.000 (2007-03-29)
  387.         */
  388.         protected $FontDescent;
  389.  
  390.         /**
  391.         * @var underlining flag
  392.         * @access protected
  393.         */
  394.         protected $underline;
  395.  
  396.         /**
  397.         * @var current font info
  398.         * @access protected
  399.         */
  400.         protected $CurrentFont;
  401.  
  402.         /**
  403.         * @var current font size in points
  404.         * @access protected
  405.         */
  406.         protected $FontSizePt;
  407.  
  408.         /**
  409.         * @var current font size in user unit
  410.         * @access protected
  411.         */
  412.         protected $FontSize;
  413.  
  414.         /**
  415.         * @var commands for drawing color
  416.         * @access protected
  417.         */
  418.         protected $DrawColor;
  419.  
  420.         /**
  421.         * @var commands for filling color
  422.         * @access protected
  423.         */
  424.         protected $FillColor;
  425.  
  426.         /**
  427.         * @var commands for text color
  428.         * @access protected
  429.         */
  430.         protected $TextColor;
  431.  
  432.         /**
  433.         * @var indicates whether fill and text colors are different
  434.         * @access protected
  435.         */
  436.         protected $ColorFlag;
  437.  
  438.         /**
  439.         * @var automatic page breaking
  440.         * @access protected
  441.         */
  442.         protected $AutoPageBreak;
  443.  
  444.         /**
  445.         * @var threshold used to trigger page breaks
  446.         * @access protected
  447.         */
  448.         protected $PageBreakTrigger;
  449.  
  450.         /**
  451.         * @var flag set when processing footer
  452.         * @access protected
  453.         */
  454.         protected $InFooter = false;
  455.  
  456.         /**
  457.         * @var zoom display mode
  458.         * @access protected
  459.         */
  460.         protected $ZoomMode;
  461.  
  462.         /**
  463.         * @var layout display mode
  464.         * @access protected
  465.         */
  466.         protected $LayoutMode;
  467.  
  468.         /**
  469.         * @var title 
  470.         * @access protected
  471.         */
  472.         protected $title;
  473.  
  474.         /**
  475.         * @var subject 
  476.         * @access protected
  477.         */
  478.         protected $subject;
  479.  
  480.         /**
  481.         * @var author 
  482.         * @access protected
  483.         */
  484.         protected $author;
  485.  
  486.         /**
  487.         * @var keywords 
  488.         * @access protected
  489.         */
  490.         protected $keywords;
  491.  
  492.         /**
  493.         * @var creator 
  494.         * @access protected
  495.         */
  496.         protected $creator;
  497.  
  498.         /**
  499.         * @var alias for total number of pages
  500.         * @access protected
  501.         */
  502.         protected $AliasNbPages = '{nb}';
  503.         
  504.         /**
  505.         * @var alias for page number
  506.         * @access protected
  507.         */
  508.         protected $AliasNumPage = '{pnb}';
  509.         
  510.         /**
  511.         * @var right-bottom corner X coordinate of inserted image
  512.         * @since 2002-07-31
  513.         * @author Nicola Asuni
  514.         * @access protected
  515.         */
  516.         protected $img_rb_x;
  517.  
  518.         /**
  519.         * @var right-bottom corner Y coordinate of inserted image
  520.         * @since 2002-07-31
  521.         * @author Nicola Asuni
  522.         * @access protected
  523.         */
  524.         protected $img_rb_y;
  525.  
  526.         /**
  527.         * @var image scale factor
  528.         * @since 2004-06-14
  529.         * @author Nicola Asuni
  530.         * @access protected
  531.         */
  532.         protected $imgscale = 1;
  533.  
  534.         /**
  535.         * @var boolean set to true when the input text is unicode (require unicode fonts)
  536.         * @since 2005-01-02
  537.         * @author Nicola Asuni
  538.         * @access protected
  539.         */
  540.         protected $isunicode = false;
  541.  
  542.         /**
  543.         * @var PDF version
  544.         * @since 1.5.3
  545.         * @access protected
  546.         */
  547.         protected $PDFVersion = '1.7';
  548.         
  549.         
  550.         // ----------------------
  551.         
  552.         /**
  553.          * @var Minimum distance between header and top page margin.
  554.          * @access protected
  555.          */
  556.         protected $header_margin;
  557.         
  558.         /**
  559.          * @var Minimum distance between footer and bottom page margin.
  560.          * @access protected
  561.          */
  562.         protected $footer_margin;
  563.         
  564.         /**
  565.          * @var original left margin value
  566.          * @access protected
  567.          * @since 1.53.0.TC013
  568.          */
  569.         protected $original_lMargin;
  570.         
  571.         /**
  572.          * @var original right margin value
  573.          * @access protected
  574.          * @since 1.53.0.TC013
  575.          */
  576.         protected $original_rMargin;
  577.             
  578.         /**
  579.          * @var Header font.
  580.          * @access protected
  581.          */
  582.         protected $header_font;
  583.         
  584.         /**
  585.          * @var Footer font.
  586.          * @access protected
  587.          */
  588.         protected $footer_font;
  589.         
  590.         /**
  591.          * @var Language templates.
  592.          * @access protected
  593.          */
  594.         protected $l;
  595.         
  596.         /**
  597.          * @var Barcode to print on page footer (only if set).
  598.          * @access protected
  599.          */
  600.         protected $barcode = false;
  601.         
  602.         /**
  603.          * @var If true prints header
  604.          * @access protected
  605.          */
  606.         protected $print_header = true;
  607.         
  608.         /**
  609.          * @var If true prints footer.
  610.          * @access protected
  611.          */
  612.         protected $print_footer = true;
  613.             
  614.         /**
  615.          * @var Header image logo.
  616.          * @access protected
  617.          */
  618.         protected $header_logo = '';
  619.         
  620.         /**
  621.          * @var Header image logo width in mm.
  622.          * @access protected
  623.          */
  624.         protected $header_logo_width = 30;
  625.         
  626.         /**
  627.          * @var String to print as title on document header.
  628.          * @access protected
  629.          */
  630.         protected $header_title = '';
  631.         
  632.         /**
  633.          * @var String to print on document header.
  634.          * @access protected
  635.          */
  636.         protected $header_string = '';
  637.         
  638.         /**
  639.          * @var Default number of columns for html table.
  640.          * @access protected
  641.          */
  642.         protected $default_table_columns = 4;
  643.         
  644.         
  645.         // variables for html parser
  646.         
  647.         /**
  648.          * @var HTML PARSER: array to store current link and rendering styles.
  649.          * @access protected
  650.          */
  651.         protected $HREF = array();
  652.         
  653.         /**
  654.          * @var store a list of available fonts on filesystem.
  655.          * @access protected
  656.          */
  657.         protected $fontlist = array();
  658.         
  659.         /**
  660.          * @var current foreground color
  661.          * @access protected
  662.          */
  663.         protected $fgcolor;
  664.                         
  665.         /**
  666.          * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  667.          * @access protected
  668.          */
  669.         protected $listordered = array();
  670.         
  671.         /**
  672.          * @var HTML PARSER: array count list items on nested lists.
  673.          * @access protected
  674.          */
  675.         protected $listcount = array();
  676.         
  677.         /**
  678.          * @var HTML PARSER: current list nesting level.
  679.          * @access protected
  680.          */
  681.         protected $listnum = 0;
  682.         
  683.         /**
  684.          * @var HTML PARSER: indent amount for lists.
  685.          * @access protected
  686.          */
  687.         protected $listindent;
  688.         
  689.         /**
  690.          * @var current background color
  691.          * @access protected
  692.          */
  693.         protected $bgcolor;
  694.         
  695.         /**
  696.          * @var Store temporary font size in points.
  697.          * @access protected
  698.          */
  699.         protected $tempfontsize = 10;
  700.         
  701.         /**
  702.          * @var spacer for LI tags.
  703.          * @access protected
  704.          */
  705.         protected $lispacer = '';
  706.         
  707.         /**
  708.          * @var default encoding
  709.          * @access protected
  710.          * @since 1.53.0.TC010
  711.          */
  712.         protected $encoding = 'UTF-8';
  713.         
  714.         /**
  715.          * @var PHP internal encoding
  716.          * @access protected
  717.          * @since 1.53.0.TC016
  718.          */
  719.         protected $internal_encoding;
  720.         
  721.         /**
  722.          * @var indicates if the document language is Right-To-Left
  723.          * @access protected
  724.          * @since 2.0.000
  725.          */
  726.         protected $rtl = false;
  727.         
  728.         /**
  729.          * @var used to force RTL or LTR string inversion
  730.          * @access protected
  731.          * @since 2.0.000
  732.          */
  733.         protected $tmprtl = false;
  734.         
  735.         // --- Variables used for document encryption:
  736.         
  737.         /**
  738.          * Indicates whether document is protected
  739.          * @access protected
  740.          * @since 2.0.000 (2008-01-02)
  741.          */
  742.         protected $encrypted;
  743.         
  744.         /**
  745.          * U entry in pdf document
  746.          * @access protected
  747.          * @since 2.0.000 (2008-01-02)
  748.          */
  749.         protected $Uvalue;
  750.         
  751.         /**
  752.          * O entry in pdf document
  753.          * @access protected
  754.          * @since 2.0.000 (2008-01-02)
  755.          */
  756.         protected $Ovalue;
  757.         
  758.         /**
  759.          * P entry in pdf document
  760.          * @access protected
  761.          * @since 2.0.000 (2008-01-02)
  762.          */
  763.         protected $Pvalue;
  764.         
  765.         /**
  766.          * encryption object id
  767.          * @access protected
  768.          * @since 2.0.000 (2008-01-02)
  769.          */
  770.         protected $enc_obj_id;
  771.         
  772.         /**
  773.          * last RC4 key encrypted (cached for optimisation)
  774.          * @access protected
  775.          * @since 2.0.000 (2008-01-02)
  776.          */
  777.         protected $last_rc4_key;
  778.         
  779.         /**
  780.          * last RC4 computed key
  781.          * @access protected
  782.          * @since 2.0.000 (2008-01-02)
  783.          */
  784.         protected $last_rc4_key_c;
  785.         
  786.         /**
  787.          * RC4 padding
  788.          * @access protected
  789.          */
  790.         protected $padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  791.         
  792.         /**
  793.          * RC4 encryption key
  794.          * @access protected
  795.          */
  796.         protected $encryption_key;
  797.         
  798.         // --- bookmark ---
  799.         
  800.         /**
  801.          * Outlines for bookmark
  802.          * @access protected
  803.          * @since 2.1.002 (2008-02-12)
  804.          */
  805.         protected $outlines = array();
  806.         
  807.         /**
  808.          * Outline root for bookmark
  809.          * @access protected
  810.          * @since 2.1.002 (2008-02-12)
  811.          */
  812.         protected $OutlineRoot;
  813.         
  814.         
  815.         // --- javascript and form ---
  816.         
  817.         /**
  818.          * javascript code
  819.          * @access protected
  820.          * @since 2.1.002 (2008-02-12)
  821.          */
  822.         protected $javascript = '';
  823.         
  824.         /**
  825.          * javascript counter
  826.          * @access protected
  827.          * @since 2.1.002 (2008-02-12)
  828.          */
  829.         protected $n_js;
  830.  
  831.         /**
  832.          * line trough state
  833.          * @access protected
  834.          * @since 2.8.000 (2008-03-19)
  835.          */
  836.         protected $linethrough;
  837.  
  838.         // --- Variables used for User's Rights ---
  839.         // See PDF reference chapter 8.7 Digital Signatures
  840.  
  841.         /**
  842.          * If true enables user's rights on PDF reader
  843.          * @access protected
  844.          * @since 2.9.000 (2008-03-26)
  845.          */
  846.         protected $ur;
  847.  
  848.         /**
  849.          * Names specifying additional document-wide usage rights for the document.
  850.          * @access protected
  851.          * @since 2.9.000 (2008-03-26)
  852.          */
  853.         protected $ur_document;
  854.  
  855.         /**
  856.          * Names specifying additional annotation-related usage rights for the document.
  857.          * @access protected
  858.          * @since 2.9.000 (2008-03-26)
  859.          */
  860.         protected $ur_annots;
  861.  
  862.         /**
  863.          * Names specifying additional form-field-related usage rights for the document.
  864.          * @access protected
  865.          * @since 2.9.000 (2008-03-26)
  866.          */
  867.         protected $ur_form;
  868.  
  869.         /**
  870.          * Names specifying additional signature-related usage rights for the document.
  871.          * @access protected
  872.          * @since 2.9.000 (2008-03-26)
  873.          */
  874.         protected $ur_signature;
  875.  
  876.         /**
  877.          * Dot Per Inch Document Resolution (do not change)
  878.          * @access protected
  879.          * @since 3.0.000 (2008-03-27)
  880.          */
  881.         protected $dpi = 72;
  882.         
  883.         /**
  884.          * Array of page numbers were a new page group was started
  885.          * @access protected
  886.          * @since 3.0.000 (2008-03-27)
  887.          */
  888.         protected $newpagegroup = array();
  889.         
  890.         /**
  891.          * Contains the number of pages of the groups
  892.          * @access protected
  893.          * @since 3.0.000 (2008-03-27)
  894.          */
  895.         protected $pagegroups;
  896.         
  897.         /**
  898.          * Contains the alias of the current page group
  899.          * @access protected
  900.          * @since 3.0.000 (2008-03-27)
  901.          */
  902.         protected $currpagegroup
  903.         
  904.         /**
  905.          * Restrict the rendering of some elements to screen or printout.
  906.          * @access protected
  907.          * @since 3.0.000 (2008-03-27)
  908.          */
  909.         protected $visibility = 'all';
  910.         
  911.         /**
  912.          * Print visibility.
  913.          * @access protected
  914.          * @since 3.0.000 (2008-03-27)
  915.          */
  916.         protected $n_ocg_print;
  917.         
  918.         /**
  919.          * View visibility.
  920.          * @access protected
  921.          * @since 3.0.000 (2008-03-27)
  922.          */
  923.         protected $n_ocg_view;
  924.         
  925.         /**
  926.          * Array of transparency objects and parameters.
  927.          * @access protected
  928.          * @since 3.0.000 (2008-03-27)
  929.          */
  930.         protected $extgstates;
  931.         
  932.         /**
  933.          * Set the default JPEG compression quality (1-100)
  934.          * @access protected
  935.          * @since 3.0.000 (2008-03-27)
  936.          */
  937.         protected $jpeg_quality;
  938.                 
  939.         /**
  940.          * Default cell height ratio.
  941.          * @access protected
  942.          * @since 3.0.014 (2008-05-23)
  943.          */
  944.         protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  945.         
  946.         /**
  947.          * PDF viewer preferences.
  948.          * @access protected
  949.          * @since 3.1.000 (2008-06-09)
  950.          */
  951.         protected $viewer_preferences;
  952.         
  953.         /**
  954.          * A name object specifying how the document should be displayed when opened.
  955.          * @access protected
  956.          * @since 3.1.000 (2008-06-09)
  957.          */
  958.         protected $PageMode;
  959.         
  960.         /**
  961.          * Array for storing gradient information.
  962.          * @access protected
  963.          * @since 3.1.000 (2008-06-09)
  964.          */
  965.         protected $gradients = array();
  966.         
  967.         /**
  968.          * Array used to store positions inside the pages buffer.
  969.          * keys are the page numbers
  970.          * @access protected
  971.          * @since 3.2.000 (2008-06-26)
  972.          */
  973.         protected $intmrk = array();
  974.         
  975.         /**
  976.          * Array used to store footer positions of each page.
  977.          * @access protected
  978.          * @since 3.2.000 (2008-07-01)
  979.          */
  980.         protected $footerpos = array();
  981.         
  982.         
  983.         /**
  984.          * Array used to store footer lenght of each page.
  985.          * @access protected
  986.          * @since 4.0.014 (2008-07-29)
  987.          */
  988.         protected $footerlen = array();
  989.         
  990.         /**
  991.          * True if a newline is created.
  992.          * @access protected
  993.          * @since 3.2.000 (2008-07-01)
  994.          */
  995.         protected $newline = true;
  996.         
  997.         /**
  998.          * End position of the latest inserted line
  999.          * @access protected
  1000.          * @since 3.2.000 (2008-07-01)
  1001.          */
  1002.         protected $endlinex = 0;
  1003.         
  1004.         /**
  1005.          * PDF string for last line width
  1006.          * @access protected
  1007.          * @since 4.0.006 (2008-07-16)
  1008.          */
  1009.         protected $linestyleWidth = '';
  1010.         
  1011.         /**
  1012.          * PDF string for last line width
  1013.          * @access protected
  1014.          * @since 4.0.006 (2008-07-16)
  1015.          */
  1016.         protected $linestyleCap = '0 J';
  1017.         
  1018.         /**
  1019.          * PDF string for last line width
  1020.          * @access protected
  1021.          * @since 4.0.006 (2008-07-16)
  1022.          */
  1023.         protected $linestyleJoin = '0 j';
  1024.         
  1025.         /**
  1026.          * PDF string for last line width
  1027.          * @access protected
  1028.          * @since 4.0.006 (2008-07-16)
  1029.          */
  1030.         protected $linestyleDash = '[] 0 d';
  1031.         
  1032.         /**
  1033.          * True if marked-content sequence is open
  1034.          * @access protected
  1035.          * @since 4.0.013 (2008-07-28)
  1036.          */
  1037.         protected $openMarkedContent = false;
  1038.         
  1039.         /**
  1040.          * Count the latest inserted vertical spaces on HTML
  1041.          * @access protected
  1042.          * @since 4.0.021 (2008-08-24)
  1043.          */
  1044.         protected $htmlvspace = 0;
  1045.         
  1046.         /**
  1047.          * Array of Spot colors
  1048.          * @access protected
  1049.          * @since 4.0.024 (2008-09-12)
  1050.          */
  1051.         protected $spot_colors = array();
  1052.         
  1053.         /**
  1054.          * Symbol used for HTML unordered list items
  1055.          * @access protected
  1056.          * @since 4.0.028 (2008-09-26)
  1057.          */
  1058.         protected $lisymbol = '';
  1059.         
  1060.         /**
  1061.          * String used to mark the beginning and end of EPS image blocks
  1062.          * @access protected
  1063.          * @since 4.1.000 (2008-10-18)
  1064.          */
  1065.         protected $epsmarker = 'x#!#EPS#!#x';
  1066.         
  1067.         /**
  1068.          * Array of transformation matrix
  1069.          * @access protected
  1070.          * @since 4.2.000 (2008-10-29)
  1071.          */
  1072.         protected $transfmatrix = array();
  1073.         
  1074.         /**
  1075.          * Booklet mode for double-sided pages
  1076.          * @access protected
  1077.          * @since 4.2.000 (2008-10-29)
  1078.          */
  1079.         protected $booklet = false;
  1080.         
  1081.         /**
  1082.          * Epsilon value used for float calculations
  1083.          * @access protected
  1084.          * @since 4.2.000 (2008-10-29)
  1085.          */
  1086.         protected $feps = 0.001;
  1087.         
  1088.         /**
  1089.          * Array used for custom vertical spaces for HTML tags
  1090.          * @access protected
  1091.          * @since 4.2.001 (2008-10-30)
  1092.          */
  1093.         protected $tagvspaces = array();
  1094.         
  1095.         /**
  1096.          * @var HTML PARSER: custom indent amount for lists.
  1097.          *  Negative value means disabled.
  1098.          * @access protected
  1099.          * @since 4.2.007 (2008-11-12)
  1100.          */
  1101.         protected $customlistindent = -1;
  1102.         
  1103.         /**
  1104.          * @var if true keeps the border open for the cell sides that cross the page.
  1105.          * @access protected
  1106.          * @since 4.2.010 (2008-11-14)
  1107.          */
  1108.         protected $opencell = true;
  1109.         
  1110.         /**
  1111.          * @var array of files to embedd
  1112.          * @access protected
  1113.          * @since 4.4.000 (2008-12-07)
  1114.          */
  1115.         protected $embeddedfiles = array();
  1116.         
  1117.         /**
  1118.          * @var boolean true when inside html pre tag
  1119.          * @access protected
  1120.          * @since 4.4.001 (2008-12-08)
  1121.          */
  1122.         protected $premode = false;
  1123.                 
  1124.         /**
  1125.          * Array used to store positions of graphics transformation blocks inside the page buffer.
  1126.          * keys are the page numbers
  1127.          * @access protected
  1128.          * @since 4.4.002 (2008-12-09)
  1129.          */
  1130.         protected $transfmrk = array();
  1131.                 
  1132.         /**
  1133.          * Default color for html links
  1134.          * @access protected
  1135.          * @since 4.4.003 (2008-12-09)
  1136.          */
  1137.         protected $htmlLinkColorArray = array(00255);
  1138.         
  1139.         /**
  1140.          * Default font style to add to html links
  1141.          * @access protected
  1142.          * @since 4.4.003 (2008-12-09)
  1143.          */
  1144.         protected $htmlLinkFontStyle = 'U';
  1145.         
  1146.         /**
  1147.          * Counts the number of pages.
  1148.          * @access protected
  1149.          * @since 4.5.000 (2008-12-31)
  1150.          */
  1151.         protected $numpages = 0;
  1152.         
  1153.         /**
  1154.          * Array containing page lenghts in bytes.
  1155.          * @access protected
  1156.          * @since 4.5.000 (2008-12-31)
  1157.          */
  1158.         protected $pagelen = array();
  1159.         
  1160.         /**
  1161.          * Counts the number of pages.
  1162.          * @access protected
  1163.          * @since 4.5.000 (2008-12-31)
  1164.          */
  1165.         protected $numimages = 0;
  1166.         
  1167.         /**
  1168.          * Store the image keys.
  1169.          * @access protected
  1170.          * @since 4.5.000 (2008-12-31)
  1171.          */
  1172.         protected $imagekeys = array();
  1173.         
  1174.         /**
  1175.          * Lenght of the buffer in bytes.
  1176.          * @access protected
  1177.          * @since 4.5.000 (2008-12-31)
  1178.          */
  1179.         protected $bufferlen = 0;
  1180.         
  1181.         /**
  1182.          * If true enables disk caching.
  1183.          * @access protected
  1184.          * @since 4.5.000 (2008-12-31)
  1185.          */
  1186.         protected $diskcache = false;
  1187.         
  1188.         /**
  1189.          * Counts the number of fonts.
  1190.          * @access protected
  1191.          * @since 4.5.000 (2009-01-02)
  1192.          */
  1193.         protected $numfonts = 0;
  1194.         
  1195.         /**
  1196.          * Store the font keys.
  1197.          * @access protected
  1198.          * @since 4.5.000 (2009-01-02)
  1199.          */
  1200.         protected $fontkeys = array();
  1201.         
  1202.         /**
  1203.          * Store the fage status (true when opened, false when closed).
  1204.          * @access protected
  1205.          * @since 4.5.000 (2009-01-02)
  1206.          */
  1207.         protected $pageopen = array();
  1208.         
  1209.         //------------------------------------------------------------
  1210.         // METHODS
  1211.         //------------------------------------------------------------
  1212.  
  1213.         /**
  1214.          * This is the class constructor.
  1215.          * It allows to set up the page format, the orientation and
  1216.          * the measure unit used in all the methods (except for the font sizes).
  1217.          * @since 1.0
  1218.          * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  1219.          * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1220.          * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1221.          * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1222.          * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1223.          * @param String $encoding charset encoding; default is UTF-8
  1224.          */
  1225.         public function __construct($orientation='P'$unit='mm'$format='A4'$unicode=true$encoding='UTF-8'$diskcache=false{
  1226.             /* Set internal character encoding to ASCII */
  1227.             if (function_exists('mb_internal_encoding'AND mb_internal_encoding()) {
  1228.                 $this->internal_encoding = mb_internal_encoding();
  1229.                 mb_internal_encoding('ASCII');
  1230.             }
  1231.             // set disk caching
  1232.             $this->diskcache = $diskcache true false;
  1233.             // set language direction
  1234.             $this->rtl = $this->l['a_meta_dir']=='rtl' true false;
  1235.             $this->tmprtl = false;
  1236.             //Some checks
  1237.             $this->_dochecks();
  1238.             //Initialization of properties
  1239.             $this->isunicode = $unicode;
  1240.             $this->page = 0;
  1241.             $this->transfmrk[0array();
  1242.             $this->pagedim = array();
  1243.             $this->n = 2;
  1244.             $this->buffer = '';
  1245.             $this->pages = array();
  1246.             $this->state = 0;
  1247.             $this->fonts = array();
  1248.             $this->FontFiles = array();
  1249.             $this->diffs = array();
  1250.             $this->images = array();
  1251.             $this->links = array();
  1252.             $this->gradients = array();
  1253.             $this->InFooter = false;
  1254.             $this->lasth = 0;
  1255.             $this->FontFamily = 'helvetica';
  1256.             $this->FontStyle = '';
  1257.             $this->FontSizePt = 12;
  1258.             $this->underline = false;
  1259.             $this->linethrough = false;
  1260.             $this->DrawColor = '0 G';
  1261.             $this->FillColor = '0 g';
  1262.             $this->TextColor = '0 g';
  1263.             $this->ColorFlag = false;
  1264.             // encryption values
  1265.             $this->encrypted = false;
  1266.             $this->last_rc4_key = '';
  1267.             $this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  1268.             //Standard Unicode fonts
  1269.             $this->CoreFonts = array(
  1270.                 'courier'=>'Courier',
  1271.                 'courierB'=>'Courier-Bold',
  1272.                 'courierI'=>'Courier-Oblique',
  1273.                 'courierBI'=>'Courier-BoldOblique',
  1274.                 'helvetica'=>'Helvetica',
  1275.                 'helveticaB'=>'Helvetica-Bold',
  1276.                 'helveticaI'=>'Helvetica-Oblique',
  1277.                 'helveticaBI'=>'Helvetica-BoldOblique',
  1278.                 'times'=>'Times-Roman',
  1279.                 'timesB'=>'Times-Bold',
  1280.                 'timesI'=>'Times-Italic',
  1281.                 'timesBI'=>'Times-BoldItalic',
  1282.                 'symbol'=>'Symbol',
  1283.                 'zapfdingbats'=>'ZapfDingbats'
  1284.             );
  1285.             //Set scale factor
  1286.             $this->setPageUnit($unit);
  1287.             // set page format and orientation
  1288.             $this->setPageFormat($format$orientation);
  1289.             //Page margins (1 cm)
  1290.             $margin 28.35 $this->k;
  1291.             $this->SetMargins($margin$margin);
  1292.             //Interior cell margin
  1293.             $this->cMargin = $margin 10;
  1294.             //Line width (0.2 mm)
  1295.             $this->LineWidth = 0.57 $this->k;
  1296.             $this->linestyleWidth = sprintf('%.2f w'($this->LineWidth * $this->k));
  1297.             $this->linestyleCap = '0 J';
  1298.             $this->linestyleJoin = '0 j';
  1299.             $this->linestyleDash = '[] 0 d';
  1300.             //Automatic page break
  1301.             $this->SetAutoPageBreak(true($margin));
  1302.             //Full width display mode
  1303.             $this->SetDisplayMode('fullwidth');
  1304.             //Compression
  1305.             $this->SetCompression(true);
  1306.             //Set default PDF version number
  1307.             $this->PDFVersion = '1.7';
  1308.             $this->encoding = $encoding;
  1309.             $this->HREF = array();
  1310.             $this->getFontsList();
  1311.             $this->fgcolor = array('R' => 0'G' => 0'B' => 0);
  1312.             $this->bgcolor = array('R' => 255'G' => 255'B' => 255);
  1313.             $this->extgstates = array();
  1314.             // user's rights
  1315.             $this->ur = false;
  1316.             $this->ur_document = '/FullSave';
  1317.             $this->ur_annots = '/Create/Delete/Modify/Copy/Import/Export';
  1318.             $this->ur_form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1319.             $this->ur_signature = '/Modify';
  1320.             // set default JPEG quality
  1321.             $this->jpeg_quality = 75;
  1322.             // initialize some settings
  1323.             $this->utf8Bidi(array(''));
  1324.             // set default font
  1325.             $this->SetFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  1326.         }
  1327.         
  1328.         /**
  1329.          * Default destructor.
  1330.          * @since 1.53.0.TC016
  1331.          */
  1332.         public function __destruct({
  1333.             // restore internal encoding
  1334.             if (isset($this->internal_encodingAND !empty($this->internal_encoding)) {
  1335.                 mb_internal_encoding($this->internal_encoding);
  1336.             }
  1337.         }
  1338.         
  1339.         /**
  1340.          * Set the units of measure for the document.
  1341.          * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1342.          * @since 3.0.015 (2008-06-06)
  1343.          */
  1344.         public function setPageUnit($unit{
  1345.         //Set scale factor
  1346.             switch (strtolower($unit)) {
  1347.                 // points
  1348.                 case 'px':
  1349.                 case 'pt'{
  1350.                     $this->k = 1;
  1351.                     break;
  1352.                 }
  1353.                 // millimeters
  1354.                 case 'mm'{
  1355.                     $this->k = $this->dpi / 25.4;
  1356.                     break;
  1357.                 }
  1358.                 // centimeters
  1359.                 case 'cm'{
  1360.                     $this->k = $this->dpi / 2.54;
  1361.                     break;
  1362.                 }
  1363.                 // inches
  1364.                 case 'in'{
  1365.                     $this->k = $this->dpi;
  1366.                     break;
  1367.                 }
  1368.                 // unsupported unit
  1369.                 default {
  1370.                     $this->Error('Incorrect unit: '.$unit);
  1371.                     break;
  1372.                 }
  1373.             }
  1374.             if (isset($this->CurOrientation)) {
  1375.                     $this->setPageOrientation($this->CurOrientation);
  1376.             }
  1377.         }
  1378.         
  1379.         /**
  1380.         * Set the page format
  1381.         * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1382.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1383.         * @since 3.0.015 (2008-06-06)
  1384.         */
  1385.         public function setPageFormat($format$orientation='P'{
  1386.             //Page format
  1387.             if (is_string($format)) {
  1388.                 // Page formats (45 standard ISO paper formats and 4 american common formats).
  1389.                 // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  1390.                 switch (strtoupper($format)) {
  1391.                     case '4A0'{$format array(4767.87,6740.79)break;}
  1392.                     case '2A0'{$format array(3370.39,4767.87)break;}
  1393.                     case 'A0'{$format array(2383.94,3370.39)break;}
  1394.                     case 'A1'{$format array(1683.78,2383.94)break;}
  1395.                     case 'A2'{$format array(1190.55,1683.78)break;}
  1396.                     case 'A3'{$format array(841.89,1190.55)break;}
  1397.                     case 'A4'default{$format array(595.28,841.89)break;}
  1398.                     case 'A5'{$format array(419.53,595.28)break;}
  1399.                     case 'A6'{$format array(297.64,419.53)break;}
  1400.                     case 'A7'{$format array(209.76,297.64)break;}
  1401.                     case 'A8'{$format array(147.40,209.76)break;}
  1402.                     case 'A9'{$format array(104.88,147.40)break;}
  1403.                     case 'A10'{$format array(73.70,104.88)break;}
  1404.                     case 'B0'{$format array(2834.65,4008.19)break;}
  1405.                     case 'B1'{$format array(2004.09,2834.65)break;}
  1406.                     case 'B2'{$format array(1417.32,2004.09)break;}
  1407.                     case 'B3'{$format array(1000.63,1417.32)break;}
  1408.                     case 'B4'{$format array(708.66,1000.63)break;}
  1409.                     case 'B5'{$format array(498.90,708.66)break;}
  1410.                     case 'B6'{$format array(354.33,498.90)break;}
  1411.                     case 'B7'{$format array(249.45,354.33)break;}
  1412.                     case 'B8'{$format array(175.75,249.45)break;}
  1413.                     case 'B9'{$format array(124.72,175.75)break;}
  1414.                     case 'B10'{$format array(87.87,124.72)break;}
  1415.                     case 'C0'{$format array(2599.37,3676.54)break;}
  1416.                     case 'C1'{$format array(1836.85,2599.37)break;}
  1417.                     case 'C2'{$format array(1298.27,1836.85)break;}
  1418.                     case 'C3'{$format array(918.43,1298.27)break;}
  1419.                     case 'C4'{$format array(649.13,918.43)break;}
  1420.                     case 'C5'{$format array(459.21,649.13)break;}
  1421.                     case 'C6'{$format array(323.15,459.21)break;}
  1422.                     case 'C7'{$format array(229.61,323.15)break;}
  1423.                     case 'C8'{$format array(161.57,229.61)break;}
  1424.                     case 'C9'{$format array(113.39,161.57)break;}
  1425.                     case 'C10'{$format array(79.37,113.39)break;}
  1426.                     case 'RA0'{$format array(2437.80,3458.27)break;}
  1427.                     case 'RA1'{$format array(1729.13,2437.80)break;}
  1428.                     case 'RA2'{$format array(1218.90,1729.13)break;}
  1429.                     case 'RA3'{$format array(864.57,1218.90)break;}
  1430.                     case 'RA4'{$format array(609.45,864.57)break;}
  1431.                     case 'SRA0'{$format array(2551.18,3628.35)break;}
  1432.                     case 'SRA1'{$format array(1814.17,2551.18)break;}
  1433.                     case 'SRA2'{$format array(1275.59,1814.17)break;}
  1434.                     case 'SRA3'{$format array(907.09,1275.59)break;}
  1435.                     case 'SRA4'{$format array(637.80,907.09)break;}
  1436.                     case 'LETTER'{$format array(612.00,792.00)break;}
  1437.                     case 'LEGAL'{$format array(612.00,1008.00)break;}
  1438.                     case 'EXECUTIVE'{$format array(521.86,756.00)break;}
  1439.                     case 'FOLIO'{$format array(612.00,936.00)break;}
  1440.                 }
  1441.                 $this->fwPt = $format[0];
  1442.                 $this->fhPt = $format[1];
  1443.             else {
  1444.                 $this->fwPt = $format[0$this->k;
  1445.                 $this->fhPt = $format[1$this->k;
  1446.             }
  1447.             $this->setPageOrientation($orientation);
  1448.         }
  1449.         
  1450.         /**
  1451.         * Set page orientation.
  1452.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1453.         * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1454.         * @param float $bottommargin bottom margin of the page.
  1455.         * @since 3.0.015 (2008-06-06)
  1456.         */
  1457.         public function setPageOrientation($orientation$autopagebreak=''$bottommargin=''{
  1458.             $orientation strtoupper($orientation);
  1459.             if (($orientation == 'P'OR ($orientation == 'PORTRAIT')) {
  1460.                 $this->CurOrientation = 'P';
  1461.                 $this->wPt = $this->fwPt;
  1462.                 $this->hPt = $this->fhPt;
  1463.             elseif (($orientation == 'L'OR ($orientation == 'LANDSCAPE')) {
  1464.                 $this->CurOrientation = 'L';
  1465.                 $this->wPt = $this->fhPt;
  1466.                 $this->hPt = $this->fwPt;
  1467.             else {
  1468.                 $this->Error('Incorrect orientation: '.$orientation);
  1469.             }
  1470.             $this->w = $this->wPt / $this->k;
  1471.             $this->h = $this->hPt / $this->k;
  1472.             if (empty($autopagebreak)) {
  1473.                 if (isset($this->AutoPageBreak)) {
  1474.                     $autopagebreak $this->AutoPageBreak;
  1475.                 else {
  1476.                     $autopagebreak true;
  1477.                 }
  1478.             }
  1479.             if (empty($bottommargin)) {
  1480.                 if (isset($this->bMargin)) {
  1481.                     $bottommargin $this->bMargin;
  1482.                 else {
  1483.                     // default value = 2 cm
  1484.                     $bottommargin 28.35 $this->k;
  1485.                 }
  1486.             }
  1487.             $this->SetAutoPageBreak($autopagebreak$bottommargin);
  1488.             // store page dimensions
  1489.             $this->pagedim[$this->pagearray('w' => $this->wPt'h' => $this->hPt'wk' => $this->w'hk' => $this->h'tm' => $this->tMargin'bm' => $bottommargin'lm' => $this->lMargin'rm' => $this->rMargin'pb' => $autopagebreak'or' => $this->CurOrientation'olm' => $this->original_lMargin'orm' => $this->original_rMargin);
  1490.         }
  1491.                 
  1492.         /**
  1493.          * Enable or disable Right-To-Left language mode
  1494.          * @param Boolean $enable if true enable Right-To-Left language mode.
  1495.          * @since 2.0.000 (2008-01-03)
  1496.          */
  1497.         public function setRTL($enable{
  1498.             $this->rtl = $enable true false;
  1499.             $this->tmprtl = false;
  1500.         }
  1501.         
  1502.         /**
  1503.          * Return the RTL status
  1504.          * @return boolean 
  1505.          * @since 4.0.012 (2008-07-24)
  1506.          */
  1507.         public function getRTL({
  1508.             return $this->rtl;
  1509.         }
  1510.         
  1511.         /**
  1512.         * Force temporary RTL language direction
  1513.         * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  1514.         * @since 2.1.000 (2008-01-09)
  1515.         */
  1516.         public function setTempRTL($mode{
  1517.             switch ($mode{
  1518.                 case false:
  1519.                 case 'L':
  1520.                 case 'R'{
  1521.                     $this->tmprtl = $mode;
  1522.                 }
  1523.             }
  1524.         }
  1525.         
  1526.         /**
  1527.         * Set the last cell height.
  1528.         * @param float $h cell height.
  1529.         * @author Nicola Asuni
  1530.         * @since 1.53.0.TC034
  1531.         */
  1532.         public function setLastH($h{
  1533.             $this->lasth = $h;
  1534.         }
  1535.         
  1536.         /**
  1537.         * Get the last cell height.
  1538.         * @return last cell height
  1539.         * @since 4.0.017 (2008-08-05)
  1540.         */
  1541.         public function getLastH({
  1542.             return $this->lasth;
  1543.         }
  1544.         
  1545.         /**
  1546.         * Set the image scale.
  1547.         * @param float $scale image scale.
  1548.         * @author Nicola Asuni
  1549.         * @since 1.5.2
  1550.         */
  1551.         public function setImageScale($scale{
  1552.             $this->imgscale = $scale;
  1553.         }
  1554.  
  1555.         /**
  1556.         * Returns the image scale.
  1557.         * @return float image scale.
  1558.         * @author Nicola Asuni
  1559.         * @since 1.5.2
  1560.         */
  1561.         public function getImageScale({
  1562.             return $this->imgscale;
  1563.         }
  1564.  
  1565.         /**
  1566.         * Returns the page width in units.
  1567.         * @return int page width.
  1568.         * @author Nicola Asuni
  1569.         * @since 1.5.2
  1570.         */
  1571.         public function getPageWidth({
  1572.             return $this->w;
  1573.         }
  1574.  
  1575.         /**
  1576.         * Returns the page height in units.
  1577.         * @return int page height.
  1578.         * @author Nicola Asuni
  1579.         * @since 1.5.2
  1580.         */
  1581.         public function getPageHeight({
  1582.             return $this->h;
  1583.         }
  1584.  
  1585.         /**
  1586.         * Returns the page break margin.
  1587.         * @return int page break margin.
  1588.         * @author Nicola Asuni
  1589.         * @since 1.5.2
  1590.         */
  1591.         public function getBreakMargin({
  1592.             return $this->bMargin;
  1593.         }
  1594.  
  1595.         /**
  1596.         * Returns the scale factor (number of points in user unit).
  1597.         * @return int scale factor.
  1598.         * @author Nicola Asuni
  1599.         * @since 1.5.2
  1600.         */
  1601.         public function getScaleFactor({
  1602.             return $this->k;
  1603.         }
  1604.  
  1605.         /**
  1606.         * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  1607.         * @param float $left Left margin.
  1608.         * @param float $top Top margin.
  1609.         * @param float $right Right margin. Default value is the left one.
  1610.         * @since 1.0
  1611.         * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  1612.         */
  1613.         public function SetMargins($left$top$right=-1{
  1614.             //Set left, top and right margins
  1615.             $this->lMargin = $left;
  1616.             $this->tMargin = $top;
  1617.             if ($right == -1{
  1618.                 $right $left;
  1619.             }
  1620.             $this->rMargin = $right;
  1621.         }
  1622.  
  1623.         /**
  1624.         * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
  1625.         * @param float $margin The margin.
  1626.         * @since 1.4
  1627.         * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1628.         */
  1629.         public function SetLeftMargin($margin{
  1630.             //Set left margin
  1631.             $this->lMargin=$margin;
  1632.             if (($this->page > 0AND ($this->x < $margin)) {
  1633.                 $this->x = $margin;
  1634.             }
  1635.         }
  1636.  
  1637.         /**
  1638.         * Defines the top margin. The method can be called before creating the first page.
  1639.         * @param float $margin The margin.
  1640.         * @since 1.5
  1641.         * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1642.         */
  1643.         public function SetTopMargin($margin{
  1644.             //Set top margin
  1645.             $this->tMargin=$margin;
  1646.             if (($this->page > 0AND ($this->y < $margin)) {
  1647.                 $this->y = $margin;
  1648.             }
  1649.         }
  1650.  
  1651.         /**
  1652.         * Defines the right margin. The method can be called before creating the first page.
  1653.         * @param float $margin The margin.
  1654.         * @since 1.5
  1655.         * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1656.         */
  1657.         public function SetRightMargin($margin{
  1658.             $this->rMargin=$margin;
  1659.             if (($this->page > 0AND ($this->x > ($this->w - $margin))) {
  1660.                 $this->x = $this->w - $margin;
  1661.             }
  1662.         }
  1663.  
  1664.         /**
  1665.         * Set the internal Cell padding.
  1666.         * @param float $pad internal padding.
  1667.         * @since 2.1.000 (2008-01-09)
  1668.         * @see Cell(), SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1669.         */
  1670.         public function SetCellPadding($pad{
  1671.             $this->cMargin = $pad;
  1672.         }
  1673.  
  1674.         /**
  1675.         * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
  1676.         * @param boolean $auto Boolean indicating if mode should be on or off.
  1677.         * @param float $margin Distance from the bottom of the page.
  1678.         * @since 1.0
  1679.         * @see Cell(), MultiCell(), AcceptPageBreak()
  1680.         */
  1681.         public function SetAutoPageBreak($auto$margin=0{
  1682.             //Set auto page break mode and triggering margin
  1683.             $this->AutoPageBreak = $auto;
  1684.             $this->bMargin = $margin;
  1685.             $this->PageBreakTrigger = $this->h - $margin;
  1686.         }
  1687.  
  1688.         /**
  1689.         * Defines the way the document is to be displayed by the viewer.
  1690.         * @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  1691.         * @param string $layout The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  1692.         * @param string $mode A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  1693.         * @since 1.2
  1694.         */
  1695.         public function SetDisplayMode($zoom$layout='SinglePage'$mode='UseNone'{
  1696.             //Set display mode in viewer
  1697.             if (($zoom == 'fullpage'OR ($zoom == 'fullwidth'OR ($zoom == 'real'OR ($zoom == 'default'OR (!is_string($zoom))) {
  1698.                 $this->ZoomMode = $zoom;
  1699.             else {
  1700.                 $this->Error('Incorrect zoom display mode: '.$zoom);
  1701.             }
  1702.             switch ($layout{
  1703.                 case 'default':
  1704.                 case 'single':
  1705.                 case 'SinglePage'{
  1706.                     $this->LayoutMode = 'SinglePage';
  1707.                     break;
  1708.                 }
  1709.                 case 'continuous':
  1710.                 case 'OneColumn'{
  1711.                     $this->LayoutMode = 'OneColumn';
  1712.                     break;
  1713.                 }
  1714.                 case 'two':
  1715.                 case 'TwoColumnLeft'{
  1716.                     $this->LayoutMode = 'TwoColumnLeft';
  1717.                     break;
  1718.                 }
  1719.                 case 'TwoColumnRight'{
  1720.                     $this->LayoutMode = 'TwoColumnRight';
  1721.                     break;
  1722.                 }
  1723.                 case 'TwoPageLeft'{
  1724.                     $this->LayoutMode = 'TwoPageLeft';
  1725.                     break;
  1726.                 }
  1727.                 case 'TwoPageRight'{
  1728.                     $this->LayoutMode = 'TwoPageRight';
  1729.                     break;
  1730.                 }
  1731.                 default{
  1732.                     $this->LayoutMode = 'SinglePage';
  1733.                 }
  1734.             }
  1735.             switch ($mode{
  1736.                 case 'UseNone'{
  1737.                     $this->PageMode = 'UseNone';
  1738.                     break;
  1739.                 }
  1740.                 case 'UseOutlines'{
  1741.                     $this->PageMode = 'UseOutlines';
  1742.                     break;
  1743.                 }
  1744.                 case 'UseThumbs'{
  1745.                     $this->PageMode = 'UseThumbs';
  1746.                     break;
  1747.                 }
  1748.                 case 'FullScreen'{
  1749.                     $this->PageMode = 'FullScreen';
  1750.                     break;
  1751.                 }
  1752.                 case 'UseOC'{
  1753.                     $this->PageMode = 'UseOC';
  1754.                     break;
  1755.                 }
  1756.                 case ''{
  1757.                     $this->PageMode = 'UseAttachments';
  1758.                     break;
  1759.                 }
  1760.                 default{
  1761.                     $this->PageMode = 'UseNone';
  1762.                 }
  1763.             }
  1764.         }
  1765.  
  1766.         /**
  1767.         * Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
  1768.         * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  1769.         * @param boolean $compress Boolean indicating if compression must be enabled.
  1770.         * @since 1.4
  1771.         */
  1772.         public function SetCompression($compress{
  1773.             //Set page compression
  1774.             if (function_exists('gzcompress')) {
  1775.                 $this->compress = $compress;
  1776.             else {
  1777.                 $this->compress = false;
  1778.             }
  1779.         }
  1780.  
  1781.         /**
  1782.         * Defines the title of the document.
  1783.         * @param string $title The title.
  1784.         * @since 1.2
  1785.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  1786.         */
  1787.         public function SetTitle($title{
  1788.             //Title of document
  1789.             $this->title = $title;
  1790.         }
  1791.  
  1792.         /**
  1793.         * Defines the subject of the document.
  1794.         * @param string $subject The subject.
  1795.         * @since 1.2
  1796.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  1797.         */
  1798.         public function SetSubject($subject{
  1799.             //Subject of document
  1800.             $this->subject = $subject;
  1801.         }
  1802.  
  1803.         /**
  1804.         * Defines the author of the document.
  1805.         * @param string $author The name of the author.
  1806.         * @since 1.2
  1807.         * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  1808.         */
  1809.         public function SetAuthor($author{
  1810.             //Author of document
  1811.             $this->author = $author;
  1812.         }
  1813.  
  1814.         /**
  1815.         * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  1816.         * @param string $keywords The list of keywords.
  1817.         * @since 1.2
  1818.         * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  1819.         */
  1820.         public function SetKeywords($keywords{
  1821.             //Keywords of document
  1822.             $this->keywords = $keywords;
  1823.         }
  1824.  
  1825.         /**
  1826.         * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  1827.         * @param string $creator The name of the creator.
  1828.         * @since 1.2
  1829.         * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  1830.         */
  1831.         public function SetCreator($creator{
  1832.             //Creator of document
  1833.             $this->creator = $creator;
  1834.         }
  1835.         
  1836.         /**
  1837.         * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
  1838.         * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  1839.         * @param string $msg The error message
  1840.         * @since 1.0
  1841.         */
  1842.         public function Error($msg{
  1843.             //Fatal error
  1844.             die('<strong>TCPDF ERROR: </strong>'.$msg);
  1845.         }
  1846.  
  1847.         /**
  1848.         * This method begins the generation of the PDF document.
  1849.         * It is not necessary to call it explicitly because AddPage() does it automatically.
  1850.         * Note: no page is created by this method
  1851.         * @since 1.0
  1852.         * @see AddPage(), Close()
  1853.         */
  1854.         public function Open({
  1855.             //Begin document
  1856.             $this->state = 1;
  1857.         }
  1858.  
  1859.         /**
  1860.         * Terminates the PDF document.
  1861.         * It is not necessary to call this method explicitly because Output() does it automatically.
  1862.         * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  1863.         * @since 1.0
  1864.         * @see Open(), Output()
  1865.         */
  1866.         public function Close({
  1867.             if ($this->state == 3{
  1868.                 return;
  1869.             }
  1870.             if ($this->page == 0{
  1871.                 $this->AddPage();
  1872.             }
  1873.             // close page
  1874.             $this->endPage();
  1875.             // close document
  1876.             $this->_enddoc();
  1877.         }
  1878.         
  1879.         /**
  1880.         * Move pointer at the specified document page and update page dimensions.
  1881.         * @param int $pnum page number
  1882.         * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  1883.         * @since 2.1.000 (2008-01-07)
  1884.         * @see getPage(), lastpage(), getNumPages()
  1885.         */
  1886.         public function setPage($pnum$resetmargins=false{
  1887.             if (($pnum 0AND ($pnum <= $this->numpages)) {
  1888.                 $this->state = 2;
  1889.                 // save current graphic settings
  1890.                 $gvars $this->getGraphicVars();
  1891.                 $oldpage $this->page;
  1892.                 $this->page = $pnum;
  1893.                 $this->wPt = $this->pagedim[$this->page]['w'];
  1894.                 $this->hPt = $this->pagedim[$this->page]['h'];
  1895.                 $this->w = $this->wPt / $this->k;
  1896.                 $this->h = $this->hPt / $this->k;
  1897.                 $this->tMargin = $this->pagedim[$this->page]['tm'];
  1898.                 $this->bMargin = $this->pagedim[$this->page]['bm'];
  1899.                 $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  1900.                 $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  1901.                 $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  1902.                 $this->CurOrientation = $this->pagedim[$this->page]['or'];
  1903.                 $this->SetAutoPageBreak($this->AutoPageBreak$this->bMargin);
  1904.                 // restore graphic settings
  1905.                 $this->setGraphicVars($gvars);
  1906.                 if ($resetmargins{
  1907.                     $this->lMargin = $this->pagedim[$this->page]['olm'];
  1908.                     $this->rMargin = $this->pagedim[$this->page]['orm'];
  1909.                     $this->SetY($this->tMargin);
  1910.                 else {
  1911.                     // account for booklet mode
  1912.                     if ($this->pagedim[$this->page]['olm'!= $this->pagedim[$oldpage]['olm']{
  1913.                         $deltam $this->pagedim[$this->page]['olm'$this->pagedim[$this->page]['orm'];
  1914.                         $this->lMargin += $deltam;
  1915.                         $this->rMargin -= $deltam;
  1916.                     }
  1917.                 }
  1918.             else {
  1919.                 $this->Error('Wrong page number on setPage() function.');
  1920.             }
  1921.         }
  1922.         
  1923.         /**
  1924.         * Reset pointer to the last document page.
  1925.         * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  1926.         * @since 2.0.000 (2008-01-04)
  1927.         * @see setPage(), getPage(), getNumPages()
  1928.         */
  1929.         public function lastPage($resetmargins=false{
  1930.             $this->setPage($this->getNumPages()$resetmargins);
  1931.         }
  1932.         
  1933.         /**
  1934.         * Get current document page number.
  1935.         * @return int page number
  1936.         * @since 2.1.000 (2008-01-07)
  1937.         * @see setPage(), lastpage(), getNumPages()
  1938.         */
  1939.         public function getPage({
  1940.             return $this->page;
  1941.         }
  1942.         
  1943.         
  1944.         /**
  1945.         * Get the total number of insered pages.
  1946.         * @return int number of pages
  1947.         * @since 2.1.000 (2008-01-07)
  1948.         * @see setPage(), getPage(), lastpage()
  1949.         */
  1950.         public function getNumPages({
  1951.             return $this->numpages;
  1952.         }
  1953.  
  1954.         /**
  1955.         * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer (if enabled). Then the page is added, the current position set to the top-left corner according to the left and top margins (or top-right if in RTL mode), and Header() is called to display the header (if enabled).
  1956.         * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  1957.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1958.         * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1959.         * @access public
  1960.         * @since 1.0
  1961.         * @see startPage(), endPage()
  1962.         */
  1963.         public function AddPage($orientation=''$format=''{
  1964.             if (!isset($this->original_lMargin)) {
  1965.                 $this->original_lMargin = $this->lMargin;
  1966.             }
  1967.             if (!isset($this->original_rMargin)) {
  1968.                 $this->original_rMargin = $this->rMargin;
  1969.             }
  1970.             // terminate previous page
  1971.             $this->endPage();
  1972.             // start new page
  1973.             $this->startPage($orientation$format);
  1974.         }
  1975.         
  1976.         /**
  1977.         * Terminate the current page
  1978.         * @access protected
  1979.         * @since 4.2.010 (2008-11-14)
  1980.         * @see startPage(), AddPage()
  1981.         */
  1982.         protected function endPage({
  1983.             // check if page is already closed
  1984.             if (($this->page == 0OR ($this->numpages > $this->pageOR (!$this->pageopen[$this->page])) {
  1985.                 return;
  1986.             }            
  1987.             // save current graphic settings
  1988.             $gvars $this->getGraphicVars();
  1989.             // print page footer
  1990.             $this->setFooter();
  1991.             // restore graphic settings
  1992.             $this->setGraphicVars($gvars);
  1993.             // close page
  1994.             $this->_endpage();
  1995.             // mark page as closed
  1996.             $this->pageopen[$this->pagefalse;
  1997.         }
  1998.         
  1999.         /**
  2000.         * Starts a new page to the document. The page must be closed using the endPage() function.
  2001.         * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2002.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2003.         * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  2004.         * @access protected
  2005.         * @since 4.2.010 (2008-11-14)
  2006.         * @see endPage(), AddPage()
  2007.         */
  2008.         protected function startPage($orientation=''$format=''{
  2009.             if ($this->numpages > $this->page{
  2010.                 // this page has been already added
  2011.                 $this->setPage($this->page + 1);
  2012.                 $this->SetY($this->tMargin);
  2013.                 return;
  2014.             }
  2015.             // start a new page
  2016.             if ($this->state == 0{
  2017.                 $this->Open();
  2018.             }
  2019.             ++$this->numpages;
  2020.             $this->swapMargins($this->booklet);
  2021.             // save current graphic settings
  2022.             $gvars $this->getGraphicVars();
  2023.             // start new page
  2024.             $this->_beginpage($orientation$format);
  2025.             // mark page as open
  2026.             $this->pageopen[$this->pagetrue;
  2027.             // restore graphic settings
  2028.             $this->setGraphicVars($gvars);
  2029.             // mark this point
  2030.             $this->setPageMark();
  2031.             // print page header
  2032.             $this->setHeader();
  2033.             // restore graphic settings
  2034.             $this->setGraphicVars($gvars);
  2035.             // mark this point
  2036.             $this->setPageMark();
  2037.         }
  2038.             
  2039.         /**
  2040.           * Set start-writing mark on current page for multicell borders and fills.
  2041.           * This function must be called after calling Image() function for a background image.
  2042.           * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2043.           * @access public
  2044.           * @since 4.0.016 (2008-07-30)
  2045.          */
  2046.         public function setPageMark({
  2047.             $this->intmrk[$this->page$this->pagelen[$this->page];
  2048.         }
  2049.         
  2050.         /**
  2051.           * Set header data.
  2052.          * @param string $ln header image logo
  2053.          * @param string $lw header image logo width in mm
  2054.          * @param string $ht string to print as title on document header
  2055.          * @param string $hs string to print on document header
  2056.         */
  2057.         public function setHeaderData($ln=''$lw=0$ht=''$hs=''{
  2058.             $this->header_logo = $ln;
  2059.             $this->header_logo_width = $lw;
  2060.             $this->header_title = $ht;
  2061.             $this->header_string = $hs;
  2062.         }
  2063.         
  2064.         /**
  2065.           * Returns header data:
  2066.           * <ul><li>$ret['logo'] = logo image</li><li>$ret['logo_width'] = width of the image logo in user units</li><li>$ret['title'] = header title</li><li>$ret['string'] = header description string</li></ul>
  2067.          * @return array() 
  2068.          * @since 4.0.012 (2008-07-24)
  2069.          */
  2070.         public function getHeaderData({
  2071.             $ret array();
  2072.             $ret['logo'$this->header_logo;
  2073.             $ret['logo_width'$this->header_logo_width;
  2074.             $ret['title'$this->header_title;
  2075.             $ret['string'$this->header_string;
  2076.             return $ret;
  2077.         }
  2078.         
  2079.         /**
  2080.           * Set header margin.
  2081.          * (minimum distance between header and top page margin)
  2082.          * @param int $hm distance in user units
  2083.         */
  2084.         public function setHeaderMargin($hm=10{
  2085.             $this->header_margin = $hm;
  2086.         }
  2087.         
  2088.         /**
  2089.           * Returns header margin in user units.
  2090.          * @return float 
  2091.          * @since 4.0.012 (2008-07-24)
  2092.         */
  2093.         public function getHeaderMargin({
  2094.             return $this->header_margin;
  2095.         }
  2096.         
  2097.         /**
  2098.           * Set footer margin.
  2099.          * (minimum distance between footer and bottom page margin)
  2100.          * @param int $fm distance in user units
  2101.         */
  2102.         public function setFooterMargin($fm=10{
  2103.             $this->footer_margin = $fm;
  2104.         }
  2105.         
  2106.         /**
  2107.           * Returns footer margin in user units.
  2108.          * @return float 
  2109.          * @since 4.0.012 (2008-07-24)
  2110.         */
  2111.         public function getFooterMargin({
  2112.             return $this->footer_margin;
  2113.         }
  2114.         /**
  2115.           * Set a flag to print page header.
  2116.          * @param boolean $val set to true to print the page header (default), false otherwise.
  2117.          */
  2118.         public function setPrintHeader($val=true{
  2119.             $this->print_header = $val;
  2120.         }
  2121.         
  2122.         /**
  2123.           * Set a flag to print page footer.
  2124.          * @param boolean $value set to true to print the page footer (default), false otherwise.
  2125.          */
  2126.         public function setPrintFooter($val=true{
  2127.             $this->print_footer = $val;
  2128.         }
  2129.         
  2130.         /**
  2131.           * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  2132.          * @return float 
  2133.          */
  2134.         public function getImageRBX({
  2135.             return $this->img_rb_x;
  2136.         }
  2137.         
  2138.         /**
  2139.           * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  2140.          * @return float 
  2141.          */
  2142.         public function getImageRBY({
  2143.             return $this->img_rb_y;
  2144.         }
  2145.         
  2146.         /**
  2147.           * This method is used to render the page header.
  2148.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2149.          */
  2150.         public function Header({
  2151.             $ormargins $this->getOriginalMargins();
  2152.             $headerfont $this->getHeaderFont();
  2153.             $headerdata $this->getHeaderData();
  2154.             if (($headerdata['logo']AND ($headerdata['logo'!= K_BLANK_IMAGE)) {
  2155.                 $this->Image(K_PATH_IMAGES.$headerdata['logo']$this->GetX()$this->getHeaderMargin()$headerdata['logo_width']);
  2156.                 $imgy $this->getImageRBY();
  2157.             else {
  2158.                 $imgy $this->GetY();
  2159.             }
  2160.             $cell_height round(($this->getCellHeightRatio($headerfont[2]$this->getScaleFactor()2);
  2161.             // set starting margin for text data cell
  2162.             if ($this->getRTL()) {
  2163.                 $header_x $ormargins['right'($headerdata['logo_width'1.1);
  2164.             else {
  2165.                 $header_x $ormargins['left'($headerdata['logo_width'1.1);
  2166.             }
  2167.             $this->SetTextColor(000);
  2168.             // header title
  2169.             $this->SetFont($headerfont[0]'B'$headerfont[21);
  2170.             $this->SetX($header_x);            
  2171.             $this->Cell(0$cell_height$headerdata['title']01''0''0);
  2172.             // header string
  2173.             $this->SetFont($headerfont[0]$headerfont[1]$headerfont[2]);
  2174.             $this->SetX($header_x);
  2175.             $this->MultiCell(0$cell_height$headerdata['string']0''01''''true0false);
  2176.             // print an ending header line
  2177.             $this->SetLineStyle(array('width' => 0.85 $this->getScaleFactor()'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));
  2178.             $this->SetY((2.835 $this->getScaleFactor()) max($imgy$this->GetY()));
  2179.             if ($this->getRTL()) {
  2180.                 $this->SetX($ormargins['right']);
  2181.             else {
  2182.                 $this->SetX($ormargins['left']);
  2183.             }
  2184.             $this->Cell(00'''T'0'C');
  2185.         }
  2186.         
  2187.         /**
  2188.           * This method is used to render the page footer.
  2189.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2190.          */
  2191.         public function Footer({                
  2192.             $cur_y $this->GetY();
  2193.             $ormargins $this->getOriginalMargins();
  2194.             $this->SetTextColor(000);            
  2195.             //set style for cell border
  2196.             $line_width 0.85 $this->getScaleFactor();
  2197.             $this->SetLineStyle(array('width' => $line_width'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));
  2198.             //print document barcode
  2199.             $barcode $this->getBarcode();
  2200.             if (!empty($barcode)) {
  2201.                 $this->Ln($line_width);
  2202.                 $barcode_width round(($this->getPageWidth($ormargins['left'$ormargins['right'])/3);
  2203.                 $this->write1DBarcode($barcode'C128B'$this->GetX()$cur_y $line_width$barcode_width(($this->getFooterMargin(3$line_width)0.3'''');    
  2204.             }
  2205.             if (empty($this->pagegroups)) {
  2206.                 $pagenumtxt $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  2207.             else {
  2208.                 $pagenumtxt $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  2209.             }        
  2210.             $this->SetY($cur_y);
  2211.             //Print page number
  2212.             if ($this->getRTL()) {
  2213.                 $this->SetX($ormargins['right']);
  2214.                 $this->Cell(00$pagenumtxt'T'0'L');
  2215.             else {
  2216.                 $this->SetX($ormargins['left']);
  2217.                 $this->Cell(00$pagenumtxt'T'0'R');
  2218.             }
  2219.         }
  2220.         
  2221.         /**
  2222.           * This method is used to render the page header.
  2223.           * @access protected
  2224.           * @since 4.0.012 (2008-07-24)
  2225.          */
  2226.         protected function setHeader({
  2227.             if ($this->print_header{
  2228.                 $lasth $this->lasth;
  2229.                 $this->_out('q');
  2230.                 $this->rMargin = $this->original_rMargin;
  2231.                 $this->lMargin = $this->original_lMargin;
  2232.                 $this->cMargin = 0;
  2233.                 //set current position
  2234.                 if ($this->rtl{
  2235.                     $this->SetXY($this->original_rMargin$this->header_margin);
  2236.                 else {
  2237.                     $this->SetXY($this->original_lMargin$this->header_margin);
  2238.                 }
  2239.                 $this->SetFont($this->header_font[0]$this->header_font[1]$this->header_font[2]);
  2240.                 $this->Header();
  2241.                 //restore position
  2242.                 if ($this->rtl{
  2243.                     $this->SetXY($this->original_rMargin$this->tMargin);
  2244.                 else {
  2245.                     $this->SetXY($this->original_lMargin$this->tMargin);
  2246.                 }
  2247.                 $this->_out('Q');
  2248.                 $this->lasth = $lasth;
  2249.             }
  2250.         }
  2251.         
  2252.         /**
  2253.           * This method is used to render the page footer.
  2254.           * @access protected
  2255.           * @since 4.0.012 (2008-07-24)
  2256.          */
  2257.         protected function setFooter({
  2258.             //Page footer
  2259.             $this->InFooter = true;
  2260.             // mark this point
  2261.             $this->footerpos[$this->page$this->pagelen[$this->page];
  2262.             if ($this->print_footer{
  2263.                 $lasth $this->lasth;
  2264.                 $this->_out('q');
  2265.                 $this->rMargin = $this->original_rMargin;
  2266.                 $this->lMargin = $this->original_lMargin;
  2267.                 $this->cMargin = 0;
  2268.                 //set current position
  2269.                 $footer_y $this->h - $this->footer_margin;
  2270.                 if ($this->rtl{
  2271.                     $this->SetXY($this->original_rMargin$footer_y);
  2272.                 else {
  2273.                     $this->SetXY($this->original_lMargin$footer_y);
  2274.                 }
  2275.                 $this->SetFont($this->footer_font[0]$this->footer_font[1$this->footer_font[2]);
  2276.                 $this->Footer();
  2277.                 //restore position
  2278.                 if ($this->rtl{
  2279.                     $this->SetXY($this->original_rMargin$this->tMargin);
  2280.                 else {
  2281.                     $this->SetXY($this->original_lMargin$this->tMargin);
  2282.                 }
  2283.                 $this->_out('Q');
  2284.                 $this->lasth = $lasth;
  2285.             }
  2286.             $this->footerlen[$this->page$this->pagelen[$this->page$this->footerpos[$this->page];
  2287.             $this->InFooter = false;
  2288.         }
  2289.         
  2290.         /**
  2291.         * Returns the current page number.
  2292.         * @return int page number
  2293.         * @since 1.0
  2294.         * @see AliasNbPages(), getAliasNbPages()
  2295.         */
  2296.         public function PageNo({
  2297.             return $this->page;
  2298.         }
  2299.  
  2300.         /**
  2301.         * Defines a new spot color.
  2302.         * It can be expressed in RGB components or gray scale.
  2303.         * The method can be called before the first page is created and the value is retained from page to page.
  2304.         * @param int $c Cyan color for CMYK. Value between 0 and 255
  2305.         * @param int $m Magenta color for CMYK. Value between 0 and 255
  2306.         * @param int $y Yellow color for CMYK. Value between 0 and 255
  2307.         * @param int $k Key (Black) color for CMYK. Value between 0 and 255
  2308.         * @since 4.0.024 (2008-09-12)
  2309.         * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2310.         */
  2311.         public function AddSpotColor($name$c$m$y$k{
  2312.             if (!isset($this->spot_colors[$name])) {
  2313.                 $i count($this->spot_colors);
  2314.                 $this->spot_colors[$namearray('i' => $i'c' => $c'm' => $m'y' => $y'k' => $k);
  2315.             }
  2316.         }
  2317.  
  2318.         /**
  2319.         * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  2320.         * It can be expressed in RGB components or gray scale.
  2321.         * The method can be called before the first page is created and the value is retained from page to page.
  2322.         * @param array $color array of colors
  2323.         * @since 3.1.000 (2008-06-11)
  2324.         * @see SetDrawColor()
  2325.         */
  2326.         public function SetDrawColorArray($color{
  2327.             if (isset($color)) {
  2328.                 $color array_values($color);
  2329.                 $r = isset($color[0]$color[0: -1;
  2330.                 $g = isset($color[1]$color[1: -1;
  2331.                 $b = isset($color[2]$color[2: -1;
  2332.                 $k = isset($color[3]$color[3: -1;
  2333.                 if ($r >= 0{
  2334.                     $this->SetDrawColor($r$g$b$k);
  2335.                 }
  2336.             }
  2337.         }
  2338.  
  2339.         /**
  2340.         * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  2341.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2342.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2343.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2344.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2345.         * @since 1.3
  2346.         * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  2347.         */
  2348.         public function SetDrawColor($col1=0$col2=-1$col3=-1$col4=-1{
  2349.             // set default values
  2350.             if (!is_numeric($col1)) {
  2351.                 $col1 0;
  2352.             }
  2353.             if (!is_numeric($col2)) {
  2354.                 $col2 = -1;
  2355.             }
  2356.             if (!is_numeric($col3)) {
  2357.                 $col3 = -1;
  2358.             }
  2359.             if (!is_numeric($col4)) {
  2360.                 $col4 = -1;
  2361.             }
  2362.             //Set color for all stroking operations
  2363.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2364.                 // Grey scale
  2365.                 $this->DrawColor = sprintf('%.3f G'$col1/255);
  2366.             elseif ($col4 == -1{
  2367.                 // RGB
  2368.                 $this->DrawColor = sprintf('%.3f %.3f %.3f RG'$col1/255$col2/255$col3/255);
  2369.             else {
  2370.                 // CMYK
  2371.                 $this->DrawColor = sprintf('%.3f %.3f %.3f %.3f K'$col1/100$col2/100$col3/100$col4/100);
  2372.             }
  2373.             if ($this->page > 0{
  2374.                 $this->_out($this->DrawColor);
  2375.             }
  2376.         }
  2377.         
  2378.         /**
  2379.         * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  2380.         * @param string $name name of the spot color
  2381.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2382.         * @since 4.0.024 (2008-09-12)
  2383.         * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2384.         */
  2385.         public function SetDrawSpotColor($name$tint=100{
  2386.             if (!isset($this->spot_colors[$name])) {
  2387.                 $this->Error('Undefined spot color: '.$name);
  2388.             }
  2389.             $this->DrawColor = sprintf('/CS%d CS %.3f SCN'$this->spot_colors[$name]['i']$tint/100);
  2390.             if ($this->page > 0{
  2391.                 $this->_out($this->DrawColor);
  2392.             }
  2393.         }
  2394.         
  2395.         /**
  2396.         * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  2397.         * It can be expressed in RGB components or gray scale.
  2398.         * The method can be called before the first page is created and the value is retained from page to page.
  2399.         * @param array $color array of colors
  2400.         * @since 3.1.000 (2008-6-11)
  2401.         * @see SetFillColor()
  2402.         */
  2403.         public function SetFillColorArray($color{
  2404.             if (isset($color)) {
  2405.                 $color array_values($color);
  2406.                 $r = isset($color[0]$color[0: -1;
  2407.                 $g = isset($color[1]$color[1: -1;
  2408.                 $b = isset($color[2]$color[2: -1;
  2409.                 $k = isset($color[3]$color[3: -1;
  2410.                 if ($r >= 0{
  2411.                     $this->SetFillColor($r$g$b$k);
  2412.                 }
  2413.             }
  2414.         }
  2415.         
  2416.         /**
  2417.         * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  2418.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2419.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2420.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2421.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2422.         * @since 1.3
  2423.         * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  2424.         */
  2425.         public function SetFillColor($col1=0$col2=-1$col3=-1$col4=-1{
  2426.             // set default values
  2427.             if (!is_numeric($col1)) {
  2428.                 $col1 0;
  2429.             }
  2430.             if (!is_numeric($col2)) {
  2431.                 $col2 = -1;
  2432.             }
  2433.             if (!is_numeric($col3)) {
  2434.                 $col3 = -1;
  2435.             }
  2436.             if (!is_numeric($col4)) {
  2437.                 $col4 = -1;
  2438.             }
  2439.             //Set color for all filling operations
  2440.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2441.                 // Grey scale
  2442.                 $this->FillColor = sprintf('%.3f g'$col1/255);
  2443.                 $this->bgcolor = array('G' => $col1);
  2444.             elseif ($col4 == -1{
  2445.                 // RGB
  2446.                 $this->FillColor = sprintf('%.3f %.3f %.3f rg'$col1/255$col2/255$col3/255);
  2447.                 $this->bgcolor = array('R' => $col1'G' => $col2'B' => $col3);
  2448.             else {
  2449.                 // CMYK
  2450.                 $this->FillColor = sprintf('%.3f %.3f %.3f %.3f k'$col1/100$col2/100$col3/100$col4/100);
  2451.                 $this->bgcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4);
  2452.             }
  2453.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2454.             if ($this->page > 0{
  2455.                 $this->_out($this->FillColor);
  2456.             }
  2457.         }
  2458.         
  2459.         /**
  2460.         * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  2461.         * @param string $name name of the spot color
  2462.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2463.         * @since 4.0.024 (2008-09-12)
  2464.         * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  2465.         */
  2466.         public function SetFillSpotColor($name$tint=100{
  2467.             if (!isset($this->spot_colors[$name])) {
  2468.                 $this->Error('Undefined spot color: '.$name);
  2469.             }
  2470.             $this->FillColor = sprintf('/CS%d cs %.3f scn'$this->spot_colors[$name]['i']$tint/100);
  2471.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2472.             if ($this->page > 0{
  2473.                 $this->_out($this->FillColor);
  2474.             }
  2475.         }
  2476.         
  2477.         /**
  2478.         * Defines the color used for text. It can be expressed in RGB components or gray scale.
  2479.         * The method can be called before the first page is created and the value is retained from page to page.
  2480.         * @param array $color array of colors
  2481.         * @since 3.1.000 (2008-6-11)
  2482.         * @see SetFillColor()
  2483.         */
  2484.         public function SetTextColorArray($color{
  2485.             if (isset($color)) {
  2486.                 $color array_values($color);
  2487.                 $r = isset($color[0]$color[0: -1;
  2488.                 $g = isset($color[1]$color[1: -1;
  2489.                 $b = isset($color[2]$color[2: -1;
  2490.                 $k = isset($color[3]$color[3: -1;
  2491.                 if ($r >= 0{
  2492.                     $this->SetTextColor($r$g$b$k);
  2493.                 }
  2494.             }
  2495.         }
  2496.  
  2497.         /**
  2498.         * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  2499.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2500.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2501.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2502.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2503.         * @since 1.3
  2504.         * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  2505.         */
  2506.         public function SetTextColor($col1=0$col2=-1$col3=-1$col4=-1{
  2507.             // set default values
  2508.             if (!is_numeric($col1)) {
  2509.                 $col1 0;
  2510.             }
  2511.             if (!is_numeric($col2)) {
  2512.                 $col2 = -1;
  2513.             }
  2514.             if (!is_numeric($col3)) {
  2515.                 $col3 = -1;
  2516.             }
  2517.             if (!is_numeric($col4)) {
  2518.                 $col4 = -1;
  2519.             }
  2520.             //Set color for text
  2521.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2522.                 // Grey scale
  2523.                 $this->TextColor = sprintf('%.3f g'$col1/255);
  2524.                 $this->fgcolor = array('G' => $col1);
  2525.             elseif ($col4 == -1{
  2526.                 // RGB
  2527.                 $this->TextColor = sprintf('%.3f %.3f %.3f rg'$col1/255$col2/255$col3/255);
  2528.                 $this->fgcolor = array('R' => $col1'G' => $col2'B' => $col3);
  2529.             else {
  2530.                 // CMYK
  2531.                 $this->TextColor = sprintf('%.3f %.3f %.3f %.3f k'$col1/100$col2/100$col3/100$col4/100);
  2532.                 $this->fgcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4);
  2533.             }
  2534.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2535.         }
  2536.         
  2537.         /**
  2538.         * Defines the spot color used for text.
  2539.         * @param string $name name of the spot color
  2540.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2541.         * @since 4.0.024 (2008-09-12)
  2542.         * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  2543.         */
  2544.         public function SetTextSpotColor($name$tint=100{
  2545.             if (!isset($this->spot_colors[$name])) {
  2546.                 $this->Error('Undefined spot color: '.$name);
  2547.             }
  2548.             $this->TextColor = sprintf('/CS%d cs %.3f scn'$this->spot_colors[$name]['i']$tint/100);
  2549.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2550.             if ($this->page > 0{
  2551.                 $this->_out($this->TextColor);
  2552.             }
  2553.         }
  2554.  
  2555.         /**
  2556.         * Returns the length of a string in user unit. A font must be selected.<br>
  2557.         * @param string $s The string whose length is to be computed
  2558.         * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  2559.         * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li></ul> or any combination. The default value is regular.
  2560.         * @param float $fontsize Font size in points. The default value is the current size.
  2561.         * @return int string length
  2562.         * @author Nicola Asuni
  2563.         * @since 1.2
  2564.         */
  2565.         public function GetStringWidth($s$fontname=''$fontstyle=''$fontsize=0{
  2566.             return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s)$this->tmprtl)$fontname$fontstyle$fontsize);
  2567.         }
  2568.         
  2569.         /**
  2570.         * Returns the string length of an array of chars in user unit. A font must be selected.<br>
  2571.         * @param string $arr The array of chars whose total length is to be computed
  2572.         * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  2573.         * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li></ul> or any combination. The default value is regular.
  2574.         * @param float $fontsize Font size in points. The default value is the current size.
  2575.         * @return int string length
  2576.         * @author Nicola Asuni
  2577.         * @since 2.4.000 (2008-03-06)
  2578.         */
  2579.         public function GetArrStringWidth($sa$fontname=''$fontstyle=''$fontsize=0{
  2580.             // store current values
  2581.             if (!empty($fontname)) {
  2582.                 $prev_FontFamily $this->FontFamily;
  2583.                 $prev_FontStyle $this->FontStyle;
  2584.                 $prev_FontSizePt $this->FontSizePt;
  2585.                 $this->SetFont($fontname$fontstyle$fontsize);
  2586.             }
  2587.             $w 0;
  2588.             foreach ($sa as $char{
  2589.                 $w += $this->GetCharWidth($char);
  2590.             }
  2591.             // restore previous values
  2592.             if (!empty($fontname)) {
  2593.                 $this->SetFont($prev_FontFamily$prev_FontStyle$prev_FontSizePt);
  2594.             }
  2595.             return $w;
  2596.         }
  2597.         
  2598.         /**
  2599.         * Returns the length of the char in user unit for the current font.<br>
  2600.         * @param int $char The char code whose length is to be returned
  2601.         * @return int char width
  2602.         * @author Nicola Asuni
  2603.         * @since 2.4.000 (2008-03-06)
  2604.         */
  2605.         public function GetCharWidth($char{
  2606.             $cw &$this->CurrentFont['cw'];
  2607.             if (isset($cw[$char])) {
  2608.                 $w $cw[$char];
  2609.             elseif (isset($this->CurrentFont['dw'])) {
  2610.                 // default width
  2611.                 $w $this->CurrentFont['dw'];
  2612.             elseif (isset($cw[32])) {
  2613.                 // default width
  2614.                 $dw $cw[32];
  2615.             else {
  2616.                 $w 600;
  2617.             }
  2618.             return ($w $this->FontSize / 1000);
  2619.         }
  2620.         
  2621.         /**
  2622.         * Returns the numbero of characters in a string.
  2623.         * @param string $s The input string.
  2624.         * @return int number of characters
  2625.         * @since 2.0.0001 (2008-01-07)
  2626.         */
  2627.         public function GetNumChars($s{
  2628.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  2629.                 return count($this->UTF8StringToArray($s));
  2630.             
  2631.             return strlen($s);
  2632.         }
  2633.             
  2634.         /**
  2635.         * Fill the list of available fonts ($this->fontlist).
  2636.         * @access protected
  2637.         * @since 4.0.013 (2008-07-28)
  2638.         */
  2639.         protected function getFontsList({
  2640.             $fontsdir opendir($this->_getfontpath());
  2641.             while (($file readdir($fontsdir)) !== false{
  2642.                 if (substr($file-4== '.php'{
  2643.                     array_push($this->fontliststrtolower(basename($file'.php')));
  2644.                 }
  2645.             }
  2646.             closedir($fontsdir);
  2647.         }
  2648.         
  2649.         /**
  2650.         * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  2651.         * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  2652.         * The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
  2653.         * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  2654.         * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  2655.         * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  2656.         * @return array containing the font data, or false in case of error.
  2657.         * @since 1.5
  2658.         * @see SetFont()
  2659.         */
  2660.         public function AddFont($family$style=''$fontfile=''{
  2661.             if (empty($family)) {
  2662.                 if (!empty($this->FontFamily)) {
  2663.                     $family $this->FontFamily;
  2664.                 else {
  2665.                     $this->Error('Empty font family');
  2666.                 }
  2667.             }
  2668.             $family strtolower($family);
  2669.             if ((!$this->isunicodeAND ($family == 'arial')) {
  2670.                 $family 'helvetica';
  2671.             }
  2672.             if (($family == 'symbol'OR ($family == 'zapfdingbats')) {
  2673.                 $style '';
  2674.             }
  2675.             $tempstyle strtoupper($style);
  2676.             $style '';
  2677.             // underline
  2678.             if (strpos($tempstyle'U'!== false{
  2679.                 $this->underline = true;
  2680.             else {
  2681.                 $this->underline = false;
  2682.             }
  2683.             // line through (deleted)
  2684.             if (strpos($tempstyle'D'!== false{
  2685.                 $this->linethrough = true;
  2686.             else {
  2687.                 $this->linethrough = false;
  2688.             }
  2689.             // bold
  2690.             if (strpos($tempstyle'B'!== false{
  2691.                 $style .= 'B';
  2692.             }
  2693.             // oblique
  2694.             if (strpos($tempstyle'I'!== false{
  2695.                 $style .= 'I';
  2696.             }
  2697.             $bistyle $style;
  2698.             $fontkey $family.$style;
  2699.             $font_style $style.($this->underline ? 'U' '').($this->linethrough ? 'D' '');
  2700.             $fontdata array('fontkey' => $fontkey'family' => $family'style' => $font_style);
  2701.             // check if the font has been already added
  2702.             if ($this->getFontBuffer($fontkey!== false{
  2703.                 return $fontdata;
  2704.             }
  2705.             if (isset($type)) {
  2706.                 unset($type)
  2707.             }
  2708.             if (isset($cw)) {
  2709.                 unset($cw)
  2710.             }
  2711.             // get specified font directory (if any)
  2712.             $fontdir '';
  2713.             if (!empty($fontfile)) {
  2714.                 $fontdir dirname($fontfile);
  2715.                 if (empty($fontdirOR ($fontdir == '.')) {
  2716.                     $fontdir '';
  2717.                 else {
  2718.                     $fontdir .= '/';
  2719.                 }
  2720.             }
  2721.             // search and include font file
  2722.             if (empty($fontfileOR (!file_exists($fontfile))) {
  2723.                 // build a standard filenames for specified font
  2724.                 $fontfile1 str_replace(' '''$family).strtolower($style).'.php';
  2725.                 $fontfile2 str_replace(' '''$family).'.php';
  2726.                 // search files on various directories
  2727.                 if (file_exists($fontdir.$fontfile1)) {
  2728.                     $fontfile $fontdir.$fontfile1;
  2729.                 elseif (file_exists($this->_getfontpath().$fontfile1)) {
  2730.                     $fontfile $this->_getfontpath().$fontfile1;
  2731.                 elseif (file_exists($fontfile1)) {
  2732.                     $fontfile $fontfile1;
  2733.                 elseif (file_exists($fontdir.$fontfile2)) {
  2734.                     $fontfile $fontdir.$fontfile2;
  2735.                 elseif (file_exists($this->_getfontpath().$fontfile2)) {
  2736.                     $fontfile $this->_getfontpath().$fontfile2;
  2737.                 else {
  2738.                     $fontfile $fontfile2;
  2739.                 }
  2740.             }
  2741.             // include font file
  2742.             if (file_exists($fontfile)) {
  2743.                 include($fontfile);
  2744.             else {
  2745.                 $this->Error('Could not include font definition file: '.$family.'');
  2746.             }
  2747.             // check font parameters
  2748.             if ((!isset($type)) OR (!isset($cw))) {
  2749.                 $this->Error('The font definition file has a bad format: '.$fontfile.'');
  2750.             }
  2751.             if (!isset($file)) {
  2752.                 $file '';
  2753.             }
  2754.             if (!isset($enc)) {
  2755.                 $enc '';
  2756.             }
  2757.             if (!isset($dwOR empty($dw)) {
  2758.                 // set default width
  2759.                 if (isset($desc['MissingWidth']AND ($desc['MissingWidth'0)) {
  2760.                     $dw $desc['MissingWidth'];
  2761.                 elseif (isset($cw[32])) {
  2762.                     $dw $cw[32];
  2763.                 else {
  2764.                     $dw 600;
  2765.                 }
  2766.             }
  2767.             ++$this->numfonts;            
  2768.             // register CID font (all styles at once)
  2769.             if ($type == 'cidfont0'{
  2770.                 $file ''// not embedded
  2771.                 $styles array('' => '''B' => ',Bold''I' => ',Italic''BI' => ',BoldItalic');
  2772.                 $sname $name.$styles[$bistyle];
  2773.                 if ((strpos($bistyle'B'!== falseAND (isset($desc['StemV'])) AND ($desc['StemV'== 70)) {
  2774.                     $desc['StemV'120;
  2775.                 }
  2776.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => $type'name' => $sname'desc' => $desc'cidinfo' => $cidinfo'up' => $up'ut' => $ut'cw' => $cw'dw' => $dw'enc' => $enc));
  2777.             elseif ($type == 'core'{
  2778.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => 'core''name' => $this->CoreFonts[$fontkey]'up' => -100'ut' => 50'cw' => $cw'dw' => $dw));
  2779.             elseif (($type == 'TrueType'OR ($type == 'Type1')) {
  2780.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => $type'name' => $name'up' => $up'ut' => $ut'cw' => $cw'dw' => $dw'file' => $file'enc' => $enc'desc' => $desc));
  2781.             elseif ($type == 'TrueTypeUnicode'{
  2782.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => $type'name' => $name'desc' => $desc'up' => $up'ut' => $ut'cw' => $cw'dw' => $dw'enc' => $enc'file' => $file'ctg' => $ctg));
  2783.             else {
  2784.                 $this->Error('Unknow font type: '.$type.'');
  2785.             }
  2786.             if (isset($diffAND (!empty($diff))) {
  2787.                 //Search existing encodings
  2788.                 $d 0;
  2789.                 $nb count($this->diffs);
  2790.                 for($i=1$i <= $nb++$i{
  2791.                     if ($this->diffs[$i== $diff{
  2792.                         $d $i;
  2793.                         break;
  2794.                     }
  2795.                 }
  2796.                 if ($d == 0{
  2797.                     $d $nb 1;
  2798.                     $this->diffs[$d$diff;
  2799.                 }
  2800.                 $this->setFontSubBuffer($fontkey'diff'$d);
  2801.             }
  2802.             if (!empty($file)) {
  2803.                 if ((strcasecmp($type,'TrueType'== 0OR (strcasecmp($type'TrueTypeUnicode'== 0)) {
  2804.                     $this->FontFiles[$filearray('length1' => $originalsize'fontdir' => $fontdir);
  2805.                 elseif ($type != 'core'{
  2806.                     $this->FontFiles[$filearray('length1' => $size1'length2' => $size2'fontdir' => $fontdir);
  2807.                 }
  2808.             }
  2809.             return $fontdata;
  2810.         }
  2811.  
  2812.         /**
  2813.         * Sets the font used to print character strings.
  2814.         * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  2815.         * The method can be called before the first page is created and the font is retained from page to page.
  2816.         * If you just wish to change the current font size, it is simpler to call SetFontSize().
  2817.         * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the K_PATH_FONTS constant</li></ul><br />
  2818.         * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
  2819.         * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li></ul> or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
  2820.         * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
  2821.         * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  2822.         * @since 1.0
  2823.         * @see AddFont(), SetFontSize()
  2824.         */
  2825.         public function SetFont($family$style=''$size=0$fontfile=''{
  2826.             //Select a font; size given in points
  2827.             if ($size == 0{
  2828.                 $size $this->FontSizePt;
  2829.             }
  2830.             // try to add font (if not already added)
  2831.             $fontdata $this->AddFont($family$style$fontfile);
  2832.             $this->FontFamily = $fontdata['family'];
  2833.             $this->FontStyle = $fontdata['style'];
  2834.             $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  2835.             $this->SetFontSize($size);
  2836.         }
  2837.  
  2838.         /**
  2839.         * Defines the size of the current font.
  2840.         * @param float $size The size (in points)
  2841.         * @since 1.0
  2842.         * @see SetFont()
  2843.         */
  2844.         public function SetFontSize($size{
  2845.             //Set font size in points
  2846.             $this->FontSizePt = $size;
  2847.             $this->FontSize = $size $this->k;
  2848.             if (isset($this->CurrentFont['desc']['Ascent']AND ($this->CurrentFont['desc']['Ascent'0)) {
  2849.                 $this->FontAscent = $this->CurrentFont['desc']['Ascent'$this->FontSize / 1000;
  2850.             else {
  2851.                 $this->FontAscent = 0.8 $this->FontSize;
  2852.             }
  2853.             if (isset($this->CurrentFont['desc']['Descent']AND ($this->CurrentFont['desc']['Descent'0)) {
  2854.                 $this->FontDescent = - $this->CurrentFont['desc']['Descent'$this->FontSize / 1000;
  2855.             else {
  2856.                 $this->FontDescent = 0.2 $this->FontSize;
  2857.             }
  2858.             if (($this->page > 0AND (isset($this->CurrentFont['i']))) {
  2859.                 $this->_out(sprintf('BT /F%d %.2f Tf ET'$this->CurrentFont['i']$this->FontSizePt));
  2860.             }
  2861.         }
  2862.  
  2863.         /**
  2864.         * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
  2865.         * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  2866.         * @since 1.5
  2867.         * @see Cell(), Write(), Image(), Link(), SetLink()
  2868.         */
  2869.         public function AddLink({
  2870.             //Create a new internal link
  2871.             $n count($this->links1;
  2872.             $this->links[$narray(00);
  2873.             return $n;
  2874.         }
  2875.  
  2876.         /**
  2877.         * Defines the page and position a link points to.
  2878.         * @param int $link The link identifier returned by AddLink()
  2879.         * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  2880.         * @param int $page Number of target page; -1 indicates the current page. This is the default value
  2881.         * @since 1.5
  2882.         * @see AddLink()
  2883.         */
  2884.         public function SetLink($link$y=0$page=-1{
  2885.             if ($y == -1{
  2886.                 $y $this->y;
  2887.             }
  2888.             if ($page == -1{
  2889.                 $page $this->page;
  2890.             }
  2891.             $this->links[$linkarray($page$y);
  2892.         }
  2893.  
  2894.         /**
  2895.         * Puts a link on a rectangular area of the page.
  2896.         * Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.
  2897.         * @param float $x Abscissa of the upper-left corner of the rectangle
  2898.         * @param float $y Ordinate of the upper-left corner of the rectangle
  2899.         * @param float $w Width of the rectangle
  2900.         * @param float $h Height of the rectangle
  2901.         * @param mixed $link URL or identifier returned by AddLink()
  2902.         * @param int $spaces number of spaces on the text to link
  2903.         * @since 1.5
  2904.         * @see AddLink(), Annotation(), Cell(), Write(), Image()
  2905.         */
  2906.         public function Link($x$y$w$h$link$spaces=0{
  2907.             $this->Annotation($x$y$w$h$linkarray('Subtype'=>'Link')$spaces);
  2908.         }
  2909.         
  2910.         /**
  2911.         * Puts a markup annotation on a rectangular area of the page.
  2912.         * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  2913.         * @param float $x Abscissa of the upper-left corner of the rectangle
  2914.         * @param float $y Ordinate of the upper-left corner of the rectangle
  2915.         * @param float $w Width of the rectangle
  2916.         * @param float $h Height of the rectangle
  2917.         * @param string $text annotation text or alternate content
  2918.         * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  2919.         * @param int $spaces number of spaces on the text to link
  2920.         * @since 4.0.018 (2008-08-06)
  2921.         */
  2922.         public function Annotation($x$y$w$h$text$opt=array('Subtype'=>'Text')$spaces=0{
  2923.             // recalculate coordinates to account for graphic transformations
  2924.             if (isset($this->transfmatrix)) {
  2925.                 $maxid count($this->transfmatrix1;
  2926.                 for ($i=$maxid$i >= 0$i--{
  2927.                     $ctm $this->transfmatrix[$i];
  2928.                     if (isset($ctm['a'])) {
  2929.                         $x $x $this->k;
  2930.                         $y ($this->h - $y$this->k;
  2931.                         $w $w $this->k;
  2932.                         $h $h $this->k;
  2933.                         // top left
  2934.                         $xt $x;
  2935.                         $yt $y;
  2936.                         $x1 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  2937.                         $y1 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  2938.                         // top right
  2939.                         $xt $x $w;
  2940.                         $yt $y;
  2941.                         $x2 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  2942.                         $y2 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  2943.                         // bottom left
  2944.                         $xt $x;
  2945.                         $yt $y $h;
  2946.                         $x3 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  2947.                         $y3 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  2948.                         // bottom right
  2949.                         $xt $x $w;
  2950.                         $yt $y $h;
  2951.                         $x4 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  2952.                         $y4 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  2953.                         // new coordinates (rectangle area)
  2954.                         $x min($x1$x2$x3$x4);
  2955.                         $y max($y1$y2$y3$y4);
  2956.                         $w (max($x1$x2$x3$x4$x$this->k;
  2957.                         $h ($y min($y1$y2$y3$y4)) $this->k;
  2958.                         $x $x $this->k;
  2959.                         $y $this->h - ($y $this->k);
  2960.                     }
  2961.                 }
  2962.             }
  2963.             $this->PageAnnots[$this->page][array('x' => $x'y' => $y'w' => $w'h' => $h'txt' => $text'opt' => $opt'numspaces' => $spaces);
  2964.             if (($opt['Subtype'== 'FileAttachment'AND (!empty($opt['FS'])) AND file_exists($opt['FS']AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  2965.                 $this->embeddedfiles[basename($opt['FS'])array('file' => $opt['FS']'n' => ($this->n + 10000));
  2966.             }
  2967.         }
  2968.                     
  2969.         /**
  2970.         * Embedd the attached files.
  2971.         * @since 4.4.000 (2008-12-07)
  2972.         * @access protected
  2973.         * @see Annotation()
  2974.         */
  2975.         protected function _putEmbeddedFiles({
  2976.             reset($this->embeddedfiles);
  2977.             foreach ($this->embeddedfiles as $filename => $filedata{
  2978.                 $data file_get_contents($filedata['file']);
  2979.                 $filter '';
  2980.                 if ($this->compress{
  2981.                     $data gzcompress($data);
  2982.                     $filter ' /Filter /FlateDecode';
  2983.                 }
  2984.                 $this->offsets[$filedata['n']] $this->bufferlen;
  2985.                 $this->_out($filedata['n'].' 0 obj');
  2986.                 $this->_out('<</Type /EmbeddedFile'.$filter.' /Length '.strlen($data).' >>');
  2987.                 $this->_putstream($data);
  2988.                 $this->_out('endobj');
  2989.             }
  2990.         }
  2991.         
  2992.         /**
  2993.         * Prints a character string.
  2994.         * The origin is on the left of the first charcter, on the baseline.
  2995.         * This method allows to place a string precisely on the page.
  2996.         * @param float $x Abscissa of the origin
  2997.         * @param float $y Ordinate of the origin
  2998.         * @param string $txt String to print
  2999.         * @param int $stroke outline size in points (0 = disable)
  3000.         * @param boolean $clip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  3001.         * @since 1.0
  3002.         * @deprecated deprecated since version 4.3.005 (2008-11-25)
  3003.         * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  3004.         */
  3005.         public function Text($x$y$txt$stroke=0$clip=false{
  3006.             //Output a string
  3007.             if ($this->rtl{
  3008.                 // bidirectional algorithm (some chars may be changed affecting the line length)
  3009.                 $s $this->utf8Bidi($this->UTF8StringToArray($txt)$this->tmprtl);
  3010.                 $l $this->GetArrStringWidth($s);
  3011.                 $xr $this->w - $x $this->GetArrStringWidth($s);
  3012.             else {
  3013.                 $xr $x;
  3014.             }
  3015.             $opt '';
  3016.             if (($stroke 0AND (!$clip)) {
  3017.                 $opt .= '1 Tr '.intval($stroke).' w ';
  3018.             elseif (($stroke 0AND $clip{
  3019.                 $opt .= '5 Tr '.intval($stroke).' w ';
  3020.             elseif ($clip{
  3021.                 $opt .= '7 Tr ';
  3022.             }
  3023.             $s sprintf('BT %.2f %.2f Td %s(%s) Tj ET 0 Tr'$xr $this->k($this->h-$y$this->k$opt$this->_escapetext($txt));
  3024.             if ($this->underline AND ($txt!='')) {
  3025.                 $s .= ' '.$this->_dounderline($xr$y$txt);
  3026.             }
  3027.             if ($this->linethrough AND ($txt!='')) 
  3028.                 $s .= ' '.$this->_dolinethrough($xr$y$txt)
  3029.             }
  3030.             if ($this->ColorFlag AND (!$clip)) {
  3031.                 $s='q '.$this->TextColor.' '.$s.' Q';
  3032.             }
  3033.             $this->_out($s);
  3034.         }
  3035.  
  3036.         /**
  3037.         * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  3038.         * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  3039.         * This method is called automatically and should not be called directly by the application.
  3040.         * @return boolean 
  3041.         * @since 1.4
  3042.         * @see SetAutoPageBreak()
  3043.         */
  3044.         public function AcceptPageBreak({
  3045.             return $this->AutoPageBreak;
  3046.         }
  3047.         
  3048.         /**
  3049.         * Add page if needed.
  3050.         * @param float $h Cell height. Default value: 0.
  3051.         * @return boolean true in case of page break, false otherwise.
  3052.         * @since 3.2.000 (2008-07-01)
  3053.         * @access protected
  3054.         */
  3055.         protected function checkPageBreak($h{
  3056.             if ((($this->y + $h$this->PageBreakTriggerAND (!$this->InFooterAND ($this->AcceptPageBreak())) {
  3057.                 //Automatic page break
  3058.                 $x $this->x;
  3059.                 $this->AddPage($this->CurOrientation);
  3060.                 $this->y = $this->tMargin;
  3061.                 $oldpage $this->page - 1;
  3062.                 if ($this->rtl{
  3063.                     if ($this->pagedim[$this->page]['orm'!= $this->pagedim[$oldpage]['orm']{
  3064.                         $this->x = $x ($this->pagedim[$this->page]['orm'$this->pagedim[$oldpage]['orm']);
  3065.                     else {
  3066.                         $this->x = $x;
  3067.                     }
  3068.                 else {
  3069.                     if ($this->pagedim[$this->page]['olm'!= $this->pagedim[$oldpage]['olm']{
  3070.                         $this->x = $x ($this->pagedim[$this->page]['olm'$this->pagedim[$oldpage]['olm']);
  3071.                     else {
  3072.                         $this->x = $x;
  3073.                     }
  3074.                 }
  3075.                 return true;
  3076.             }
  3077.             return false;
  3078.         }
  3079.  
  3080.         /**
  3081.         * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  3082.         * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3083.         * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3084.         * @param float $h Cell height. Default value: 0.
  3085.         * @param string $txt String to print. Default value: empty string.
  3086.         * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3087.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  3088.         Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3089.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  3090.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3091.         * @param mixed $link URL or identifier returned by AddLink().
  3092.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3093.         * @since 1.0
  3094.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  3095.         */
  3096.         public function Cell($w$h=0$txt=''$border=0$ln=0$align=''$fill=0$link=''$stretch=0{
  3097.             //$min_cell_height = $this->FontAscent + $this->FontDescent;
  3098.             $min_cell_height $this->FontSize * $this->cell_height_ratio;
  3099.             if ($h $min_cell_height{
  3100.                 $h $min_cell_height;
  3101.             }
  3102.             $this->checkPageBreak($h);
  3103.             $this->_out($this->getCellCode($w$h$txt$border$ln$align$fill$link$stretch));
  3104.         }
  3105.         
  3106.         /**
  3107.         * Returns the PDF string code to print a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  3108.         * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3109.         * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3110.         * @param float $h Cell height. Default value: 0.
  3111.         * @param string $txt String to print. Default value: empty string.
  3112.         * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3113.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3114.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  3115.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3116.         * @param mixed $link URL or identifier returned by AddLink().
  3117.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3118.         * @since 1.0
  3119.         * @see Cell()
  3120.         */
  3121.         protected function getCellCode($w$h=0$txt=''$border=0$ln=0$align=''$fill=0$link=''$stretch=0{
  3122.             $rs ''//string to be returned
  3123.             $min_cell_height $this->FontSize * $this->cell_height_ratio;
  3124.             if ($h $min_cell_height{
  3125.                 $h $min_cell_height;
  3126.             }
  3127.             $k $this->k;
  3128.             if (empty($wOR ($w <= 0)) {
  3129.                 if ($this->rtl{
  3130.                     $w $this->x - $this->lMargin;
  3131.                 else {
  3132.                     $w $this->w - $this->rMargin - $this->x;
  3133.                 }
  3134.             }
  3135.             $s '';            
  3136.             if (($fill == 1OR ($border == 1)) {
  3137.                 if ($fill == 1{
  3138.                     $op ($border == 1'B' 'f';
  3139.                 else {
  3140.                     $op 'S';
  3141.                 }
  3142.                 if ($this->rtl{
  3143.                     $xk (($this->x  - $w$k);
  3144.                 else {
  3145.                     $xk ($this->x * $k);
  3146.                 }
  3147.                 $s .= sprintf('%.2f %.2f %.2f %.2f re %s '$xk(($this->h - $this->y$k)($w $k)(-$h $k)$op);
  3148.             }
  3149.             if (is_string($border)) {
  3150.                 $lm ($this->LineWidth / 2);
  3151.                 $x $this->x;
  3152.                 $y $this->y;
  3153.                 if (strpos($border,'L'!== false{
  3154.                     if ($this->rtl{
  3155.                         $xk ($x $w$k;
  3156.                     else {
  3157.                         $xk $x $k;
  3158.                     }
  3159.                     $s .= sprintf('%.2f %.2f m %.2f %.2f l S '$xk(($this->h - $y $lm$k)$xk(($this->h - ($y $h $lm)) $k));
  3160.                 }
  3161.                 if (strpos($border,'T'!== false{
  3162.                     if ($this->rtl{
  3163.                         $xk ($x $w $lm$k;
  3164.                         $xwk ($x $lm$k;
  3165.                     else {
  3166.                         $xk ($x $lm$k;
  3167.                         $xwk ($x $w $lm$k;
  3168.                     }
  3169.                     $s .= sprintf('%.2f %.2f m %.2f %.2f l S '$xk(($this->h - $y$k)$xwk(($this->h - $y$k));
  3170.                 }
  3171.                 if (strpos($border,'R'!== false{
  3172.                     if ($this->rtl{
  3173.                         $xk $x $k;
  3174.                     else {
  3175.                         $xk ($x $w$k;
  3176.                     }
  3177.                     $s .= sprintf('%.2f %.2f m %.2f %.2f l S '$xk(($this->h - $y $lm$k)$xk(($this->h - ($y $h $lm))$k));
  3178.                 }
  3179.                 if (strpos($border,'B'!== false{
  3180.                     if ($this->rtl{
  3181.                         $xk ($x $w $lm$k;
  3182.                         $xwk ($x $lm$k;
  3183.                     else {
  3184.                         $xk ($x $lm$k;
  3185.                         $xwk ($x $w $lm$k;
  3186.                     }
  3187.                     $s .= sprintf('%.2f %.2f m %.2f %.2f l S '$xk(($this->h - ($y $h)) $k)$xwk(($this->h - ($y $h)) $k));
  3188.                 }
  3189.             }
  3190.             if ($txt != ''{
  3191.                 // text lenght
  3192.                 $width $this->GetStringWidth($txt);
  3193.                 // ratio between cell lenght and text lenght
  3194.                 $ratio ($w ($this->cMargin)) $width;
  3195.                 
  3196.                 // stretch text if required
  3197.                 if (($stretch 0AND (($ratio 1OR (($ratio 1AND (($stretch 2== 0)))) {
  3198.                     if ($stretch 2{
  3199.                         // spacing
  3200.                         //Calculate character spacing in points
  3201.                         $char_space (($w $width ($this->cMargin)) $this->kmax($this->GetNumChars($txt)-1,1);
  3202.                         //Set character spacing
  3203.                         $rs .= sprintf('BT %.2f Tc ET '$char_space);
  3204.                     else {
  3205.                         // scaling
  3206.                         //Calculate horizontal scaling
  3207.                         $horiz_scale $ratio 100.0;
  3208.                         //Set horizontal scaling
  3209.                         $rs .= sprintf('BT %.2f Tz ET '$horiz_scale);
  3210.                     }
  3211.                     $align '';
  3212.                     $width $w ($this->cMargin);
  3213.                 else {
  3214.                     $stretch == 0;
  3215.                 }
  3216.                 if ($align == 'L'{
  3217.                     if ($this->rtl{
  3218.                         $dx $w $width $this->cMargin;
  3219.                     else {
  3220.                         $dx $this->cMargin;
  3221.                     }
  3222.                 elseif ($align == 'R'{
  3223.                     if ($this->rtl{
  3224.                         $dx $this->cMargin;
  3225.                     else {
  3226.                         $dx $w $width $this->cMargin;
  3227.                     }
  3228.                 elseif ($align == 'C'{
  3229.                     $dx ($w $width2;
  3230.                 elseif ($align == 'J'{
  3231.                     if ($this->rtl{
  3232.                         $dx $w $width $this->cMargin;
  3233.                     else {
  3234.                         $dx $this->cMargin;
  3235.                     }
  3236.                 else {
  3237.                     $dx $this->cMargin;
  3238.                 }
  3239.                 if ($this->ColorFlag{
  3240.                     $s .= 'q '.$this->TextColor.' ';
  3241.                 }
  3242.                 $txt2 $this->_escapetext($txt);
  3243.                 if ($this->rtl{
  3244.                     $xdk ($this->x - $dx $width$k;
  3245.                 else {
  3246.                     $xdk ($this->x + $dx$k;
  3247.                 }
  3248.                 // Justification
  3249.                 if ($align == 'J'{
  3250.                     // count number of spaces
  3251.                     $ns substr_count($txt' ');
  3252.                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  3253.                         // get string width without spaces
  3254.                         $width $this->GetStringWidth(str_replace(' '''$txt));
  3255.                         // calculate average space width
  3256.                         $spacewidth ($w $width ($this->cMargin)) ($ns?$ns:1$this->FontSize / $this->k;
  3257.                         // set word position to be used with TJ operator
  3258.                         $txt2 str_replace(chr(0).' '') '.(-2830 $spacewidth).' ('$txt2);
  3259.                     else {
  3260.                         // get string width
  3261.                         $width $this->GetStringWidth($txt);
  3262.                         $spacewidth (($w $width ($this->cMargin)) ($ns?$ns:1)) $this->k;
  3263.                         $rs .= sprintf('BT %.3f Tw ET '$spacewidth);
  3264.                     }
  3265.                 }
  3266.                 // calculate approximate position of the font base line
  3267.                 //$basefonty = $this->y + (($h + $this->FontAscent - $this->FontDescent)/2);
  3268.                 $basefonty $this->y + ($h/2($this->FontSize/3);
  3269.                 // print text
  3270.                 $s .= sprintf('BT %.2f %.2f Td [(%s)] TJ ET'$xdk(($this->h - $basefonty$k)$txt2);
  3271.                 if ($this->rtl{
  3272.                     $xdx $this->x - $dx $width;
  3273.                 else {
  3274.                     $xdx $this->x + $dx;
  3275.                 }
  3276.                 if ($this->underline)  {
  3277.                     $s .= ' '.$this->_dounderline($xdx$basefonty$txt);
  3278.                 }
  3279.                 if ($this->linethrough
  3280.                     $s .= ' '.$this->_dolinethrough($xdx$basefonty$txt);
  3281.                 }
  3282.                 if ($this->ColorFlag{
  3283.                     $s .= ' Q';
  3284.                 }
  3285.                 if ($link{
  3286.                     $this->Link($xdx$this->y + (($h $this->FontSize)/2)$width$this->FontSize$linksubstr_count($txtchr(32)));
  3287.                 }
  3288.             }
  3289.             // output cell
  3290.             if ($s{
  3291.                 // output cell
  3292.                 $rs .= $s;
  3293.                 // reset text stretching
  3294.                 if ($stretch 2{
  3295.                     //Reset character horizontal spacing
  3296.                     $rs .= ' BT 0 Tc ET';
  3297.                 elseif ($stretch 0{
  3298.                     //Reset character horizontal scaling
  3299.                     $rs .= ' BT 100 Tz ET';
  3300.                 }
  3301.             }
  3302.             // reset word spacing
  3303.             if (!(($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) AND ($align == 'J')) {
  3304.                 $rs .= ' BT 0 Tw ET';
  3305.             }
  3306.             $this->lasth = $h;
  3307.             if ($ln 0{
  3308.                 //Go to the beginning of the next line
  3309.                 $this->y += $h;
  3310.                 if ($ln == 1{
  3311.                     if ($this->rtl{
  3312.                         $this->x = $this->w - $this->rMargin;
  3313.                     else {
  3314.                         $this->x = $this->lMargin;
  3315.                     }
  3316.                 }
  3317.             else {
  3318.                 // go left or right by case
  3319.                 if ($this->rtl{
  3320.                     $this->x -= $w;
  3321.                 else {
  3322.                     $this->x += $w;
  3323.                 }
  3324.             }
  3325.             $gstyles ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  3326.             $rs $gstyles.$rs;
  3327.             return $rs;
  3328.         }
  3329.  
  3330.         /**
  3331.         * This method allows printing text with line breaks.
  3332.         * They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />
  3333.         * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  3334.         * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  3335.         * @param float $h Cell minimum height. The cell extends automatically if needed.
  3336.         * @param string $txt String to print
  3337.         * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3338.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
  3339.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3340.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  3341.         * @param int $x x position in user units
  3342.         * @param int $y y position in user units
  3343.         * @param boolean $reseth if true reset the last cell height (default true).
  3344.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3345.         * @param boolean $ishtml set to true if $txt is HTML content (default = false).
  3346.         * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  3347.         * @param float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false.
  3348.         * @return int Return the number of cells or 1 for html mode.
  3349.         * @since 1.3
  3350.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  3351.         */
  3352.         public function MultiCell($w$h$txt$border=0$align='J'$fill=0$ln=1$x=''$y=''$reseth=true$stretch=0$ishtml=false$autopadding=true$maxh=0{    
  3353.             if (empty($this->lasthOR $reseth{
  3354.                 //set row height
  3355.                 $this->lasth = $this->FontSize * $this->cell_height_ratio;
  3356.             }
  3357.             if (!empty($y)) {
  3358.                 $this->SetY($y);
  3359.             else {
  3360.                 $y $this->GetY();
  3361.             }
  3362.             // check for page break
  3363.             $this->checkPageBreak($h);
  3364.             $y $this->GetY();
  3365.             // get current page number
  3366.             $startpage $this->page;
  3367.             if (!empty($x)) {
  3368.                 $this->SetX($x);
  3369.             else {
  3370.                 $x $this->GetX();
  3371.             }
  3372.             if (empty($wOR ($w <= 0)) {
  3373.                 if ($this->rtl{
  3374.                     $w $this->x - $this->lMargin;
  3375.                 else {
  3376.                     $w $this->w - $this->rMargin - $this->x;
  3377.                 }
  3378.             }
  3379.             // store original margin values
  3380.             $lMargin $this->lMargin;
  3381.             $rMargin $this->rMargin;
  3382.             if ($this->rtl{
  3383.                 $this->SetRightMargin($this->w - $this->x);
  3384.                 $this->SetLeftMargin($this->x - $w);
  3385.             else {
  3386.                 $this->SetLeftMargin($this->x);
  3387.                 $this->SetRightMargin($this->w - $this->x - $w);
  3388.             }
  3389.             $starty $this->y;
  3390.             if ($autopadding{
  3391.                 // Adjust internal padding
  3392.                 if ($this->cMargin < ($this->LineWidth / 2)) {
  3393.                     $this->cMargin = ($this->LineWidth / 2);
  3394.                 }
  3395.                 // Add top space if needed
  3396.                 if (($this->lasth - $this->FontSize$this->LineWidth{
  3397.                     $this->y += $this->LineWidth / 2;
  3398.                 }
  3399.                 // add top padding
  3400.                 $this->y += $this->cMargin;
  3401.             }
  3402.             if ($ishtml{
  3403.                 // ******* Write HTML text
  3404.                 $this->writeHTML($txttrue0$resethtrue$align);
  3405.                 $nl 1;
  3406.             else {
  3407.                 // ******* Write text
  3408.                 $nl $this->Write($this->lasth$txt''0$aligntrue$stretchfalsefalse$maxh);
  3409.             }
  3410.             if ($autopadding{
  3411.                 // add bottom padding
  3412.                 $this->y += $this->cMargin;
  3413.                 // Add bottom space if needed
  3414.                 if (($this->lasth - $this->FontSize$this->LineWidth{
  3415.                     $this->y += $this->LineWidth / 2;
  3416.                 }
  3417.             }
  3418.             // Get end-of-text Y position
  3419.             $currentY $this->GetY();
  3420.             // get latest page number
  3421.             $endpage $this->page;
  3422.             // check if a new page has been created
  3423.             if ($endpage $startpage{
  3424.                 // design borders around HTML cells.
  3425.                 for ($page=$startpage$page <= $endpage++$page{
  3426.                     $this->setPage($page);
  3427.                     if ($page == $startpage{
  3428.                         $this->y = $starty// put cursor at the beginning of cell on the first page
  3429.                         $h $this->getPageHeight($starty $this->getBreakMargin();
  3430.                         $cborder $this->getBorderMode($border$position='start');
  3431.                     elseif ($page == $endpage{
  3432.                         $this->y = $this->tMargin// put cursor at the beginning of last page
  3433.                         $h $currentY $this->tMargin;
  3434.                         $cborder $this->getBorderMode($border$position='end');
  3435.                     else {
  3436.                         $this->y = $this->tMargin// put cursor at the beginning of the current page
  3437.                         $h $this->getPageHeight($this->tMargin - $this->getBreakMargin();
  3438.                         $cborder $this->getBorderMode($border$position='middle');
  3439.                     }
  3440.                     $nx $x;
  3441.                     // account for margin changes
  3442.                     if ($page $startpage{
  3443.                         if (($this->rtlAND ($this->pagedim[$page]['orm'!= $this->pagedim[$startpage]['orm'])) {
  3444.                             $nx $x ($this->pagedim[$page]['orm'$this->pagedim[$startpage]['orm']);
  3445.                         elseif ((!$this->rtlAND ($this->pagedim[$page]['olm'!= $this->pagedim[$startpage]['olm'])) {
  3446.                             $nx $x ($this->pagedim[$page]['olm'$this->pagedim[$startpage]['olm']);
  3447.                         }
  3448.                     }
  3449.                     $this->SetX($nx);
  3450.                     $ccode $this->getCellCode($w$h''$cborder1''$fill);
  3451.                     if ($cborder OR $fill{
  3452.                         $pstart substr($this->getPageBuffer($this->page)0$this->intmrk[$this->page]);
  3453.                         $pend substr($this->getPageBuffer($this->page)$this->intmrk[$this->page]);
  3454.                         $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  3455.                         $this->intmrk[$this->page+= strlen($ccode."\n");
  3456.                     }
  3457.                 }
  3458.             else {
  3459.                 $h max($h($currentY $y));
  3460.                 // put cursor at the beginning of text
  3461.                 $this->SetY($y)
  3462.                 $this->SetX($x);
  3463.                 // design a cell around the text
  3464.                 $ccode $this->getCellCode($w$h''$border1''$fill);
  3465.                 if ($border OR $fill{
  3466.                     if (end($this->transfmrk[$this->page]!== false{
  3467.                         $pagemarkkey key($this->transfmrk[$this->page]);
  3468.                         $pagemark &$this->transfmrk[$this->page][$pagemarkkey];
  3469.                     elseif ($this->InFooter{
  3470.                         $pagemark &$this->footerpos[$this->page];
  3471.                     else {
  3472.                         $pagemark &$this->intmrk[$this->page];
  3473.                     }
  3474.                     $pstart substr($this->getPageBuffer($this->page)0$pagemark);
  3475.                     $pend substr($this->getPageBuffer($this->page)$pagemark);
  3476.                     $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  3477.                     $pagemark += strlen($ccode."\n");
  3478.                 }
  3479.             }
  3480.             // Get end-of-cell Y position
  3481.             $currentY $this->GetY();
  3482.             // restore original margin values
  3483.             $this->SetLeftMargin($lMargin);
  3484.             $this->SetRightMargin($rMargin);
  3485.             if ($ln 0{
  3486.                 //Go to the beginning of the next line
  3487.                 $this->SetY($currentY);
  3488.                 if ($ln == 2{
  3489.                     $this->SetX($x $w);
  3490.                 }
  3491.             else {
  3492.                 // go left or right by case
  3493.                 $this->setPage($startpage);
  3494.                 $this->y = $y;
  3495.                 $this->SetX($x $w);
  3496.             }
  3497.             return $nl;
  3498.         }
  3499.         
  3500.         /**
  3501.         * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  3502.         * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3503.         * @param string multicell position: 'start', 'middle', 'end'
  3504.         * @return border mode
  3505.         * @access protected
  3506.         * @since 4.4.002 (2008-12-09)
  3507.         */
  3508.         protected function getBorderMode($border$position='start'{
  3509.             if ((!$this->opencellAND ($border == 1)) {
  3510.                 return 1;
  3511.             }
  3512.             $cborder '';
  3513.             switch ($position{
  3514.                 case 'start'{
  3515.                     if ($border == 1{
  3516.                         $cborder 'LTR';
  3517.                     else {
  3518.                         if (!(false === strpos($border'L'))) {
  3519.                             $cborder .= 'L';
  3520.                         }
  3521.                         if (!(false === strpos($border'T'))) {
  3522.                             $cborder .= 'T';
  3523.                         }
  3524.                         if (!(false === strpos($border'R'))) {
  3525.                             $cborder .= 'R';
  3526.                         }
  3527.                         if ((!$this->opencellAND (!(false === strpos($border'B')))) {
  3528.                             $cborder .= 'B';
  3529.                         }
  3530.                     }
  3531.                     break;
  3532.                 }
  3533.                 case 'middle'{
  3534.                     if ($border == 1{
  3535.                         $cborder 'LR';
  3536.                     else {
  3537.                         if (!(false === strpos($border'L'))) {
  3538.                             $cborder .= 'L';
  3539.                         }
  3540.                         if ((!$this->opencellAND (!(false === strpos($border'T')))) {
  3541.                             $cborder .= 'T';
  3542.                         }
  3543.                         if (!(false === strpos($border'R'))) {
  3544.                             $cborder .= 'R';
  3545.                         }
  3546.                         if ((!$this->opencellAND (!(false === strpos($border'B')))) {
  3547.                             $cborder .= 'B';
  3548.                         }
  3549.                     }
  3550.                     break;
  3551.                 }
  3552.                 case 'end'{
  3553.                     if ($border == 1{
  3554.                         $cborder 'LRB';
  3555.                     else {
  3556.                         if (!(false === strpos($border'L'))) {
  3557.                             $cborder .= 'L';
  3558.                         }
  3559.                         if ((!$this->opencellAND (!(false === strpos($border'T')))) {
  3560.                             $cborder .= 'T';
  3561.                         }
  3562.                         if (!(false === strpos($border'R'))) {
  3563.                             $cborder .= 'R';
  3564.                         }
  3565.                         if (!(false === strpos($border'B'))) {
  3566.                             $cborder .= 'B';
  3567.                         }
  3568.                     }
  3569.                     break;
  3570.                 }
  3571.                 default{
  3572.                     $cborder $border;
  3573.                     break;
  3574.                 }
  3575.             }
  3576.             return $cborder;            
  3577.         }
  3578.         
  3579.         /**
  3580.         * This method returns the estimated number of lines required to print the text.
  3581.         * @param string $txt text to print
  3582.         * @param float $w width of cell. If 0, they extend up to the right margin of the page.
  3583.         * @return int Return the estimated number of lines.
  3584.         * @since 4.5.011
  3585.         */
  3586.         public function getNumLines($txt$w=0{
  3587.             $lines 0;
  3588.             if (empty($wOR ($w <= 0)) {
  3589.                 if ($this->rtl{
  3590.                     $w $this->x - $this->lMargin;
  3591.                 else {
  3592.                     $w $this->w - $this->rMargin - $this->x;
  3593.                 }
  3594.             }
  3595.             // max column width
  3596.             $wmax $w ($this->cMargin);
  3597.             // remove carriage returns
  3598.             $txt str_replace("\r"''$txt);
  3599.             // divide text in blocks
  3600.             $txtblocks explode("\n"$txt);
  3601.             // for each block;
  3602.             foreach ($txtblocks as $block{
  3603.                 // estimate the number of lines
  3604.                 $lines += ceil($this->GetStringWidth($block$wmax);
  3605.             }
  3606.             return $lines;
  3607.         }
  3608.             
  3609.         /**
  3610.         * This method prints text from the current position.<br />
  3611.         * @param float $h Line height
  3612.         * @param string $txt String to print
  3613.         * @param mixed $link URL or identifier returned by AddLink()
  3614.         * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  3615.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  3616.         * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  3617.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3618.         * @param boolean $firstline if true prints only the first line and return the remaining string.
  3619.         * @param boolean $firstblock if true the string is the starting of a line.
  3620.         * @param float $maxh maximum height. The remaining unprinted text will be returned. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  3621.         * @return mixed Return the number of cells or the remaining string if $firstline = true.
  3622.         * @since 1.5
  3623.         */
  3624.         public function Write($h$txt$link=''$fill=0$align=''$ln=false$stretch=0$firstline=false$firstblock=false$maxh=0{
  3625.             // remove carriage returns
  3626.             $s str_replace("\r"''$txt);
  3627.             // check if string contains arabic text
  3628.             if (preg_match(K_RE_PATTERN_ARABIC$s)) {
  3629.                 $arabic true;
  3630.             else {
  3631.                 $arabic false;
  3632.             }
  3633.             // get a char width
  3634.             $chrwidth $this->GetCharWidth('.');
  3635.             // get array of chars
  3636.             $chars $this->UTF8StringToArray($s);
  3637.             // get the number of characters
  3638.             $nb count($chars);
  3639.             // handle single space character
  3640.             if (($nb == 1AND preg_match('/[\s]/'$s)) {
  3641.                 if ($this->rtl{
  3642.                     $this->x -= $this->GetStringWidth($s);
  3643.                 else {
  3644.                     $this->x += $this->GetStringWidth($s);
  3645.                 }
  3646.                 return;
  3647.             }
  3648.             // store current position
  3649.             $prevx $this->x;
  3650.             $prevy $this->y;
  3651.             // max Y
  3652.             $maxy $this->y + $maxh $h ($this->cMargin);
  3653.             // calculate remaining line width ($w)
  3654.             if ($this->rtl{
  3655.                 $w $this->x - $this->lMargin;
  3656.             else {
  3657.                 $w $this->w - $this->rMargin - $this->x;
  3658.             }
  3659.             // max column width
  3660.             $wmax $w ($this->cMargin);
  3661.             $i 0// character position
  3662.             $j 0// current starting position
  3663.             $sep = -1// position of the last blank space
  3664.             $l 0// current string lenght
  3665.             $nl 0//number of lines
  3666.             $linebreak false;
  3667.             // for each character
  3668.             while ($i $nb{
  3669.                 if (($maxh 0AND ($this->y >= $maxy) ) {
  3670.                     $firstline true;
  3671.                 }
  3672.                 //Get the current character
  3673.                 $c $chars[$i];
  3674.                 if ($c == 10// 10 = "\n" = new line
  3675.                     //Explicit line break
  3676.                     if ($align == 'J'{
  3677.                         if ($this->rtl{
  3678.                             $talign 'R';
  3679.                         else {
  3680.                             $talign 'L';
  3681.                         }
  3682.                     else {
  3683.                         $talign $align;
  3684.                     }
  3685.                     if ($firstline{
  3686.                         $startx $this->x;
  3687.                         $linew $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars$j$i)$this->tmprtl));
  3688.                         if ($this->rtl{
  3689.                             $this->endlinex = $startx $linew;
  3690.                         else {
  3691.                             $this->endlinex = $startx $linew;
  3692.                         }
  3693.                         $w $linew;
  3694.                         $tmpcmargin $this->cMargin;
  3695.                         if ($maxh == 0{
  3696.                             $this->cMargin = 0;
  3697.                         }
  3698.                     }
  3699.                     $this->Cell($w$h$this->UTF8ArrSubString($chars$j$i)01$talign$fill$link$stretch);
  3700.                     if ($firstline{
  3701.                         $this->cMargin = $tmpcmargin;
  3702.                         return ($this->UTF8ArrSubString($chars$i));
  3703.                     }
  3704.                     ++$nl;
  3705.                     $j $i 1;
  3706.                     $l 0;
  3707.                     $sep = -1;
  3708.                     // account for margin changes
  3709.                     if ((($this->y + $this->lasth$this->PageBreakTriggerAND (!$this->InFooter)) {
  3710.                         // AcceptPageBreak() may be overriden on extended classed to include margin changes
  3711.                         $this->AcceptPageBreak();
  3712.                     }
  3713.                     $w $this->getRemainingWidth();
  3714.                     $wmax $w ($this->cMargin);
  3715.                 else {
  3716.                     if (($c != 160AND preg_match('/[\s]/'$this->unichr($c))) {
  3717.                         // update last blank space position
  3718.                         $sep $i;
  3719.                     }
  3720.                     // update string length
  3721.                     if ((($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) AND ($arabic)) {
  3722.                         // with bidirectional algorithm some chars may be changed affecting the line length
  3723.                         // *** very slow ***
  3724.                         $l $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars$j$i-$j+1)$this->tmprtl));
  3725.                     else {
  3726.                         $l += $this->GetCharWidth($c);
  3727.                     }
  3728.                     if ($l $wmax{
  3729.                         // we have reached the end of column
  3730.                         if ($sep == -1{
  3731.                             // check if the line was already started
  3732.                             if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
  3733.                                 OR ((!$this->rtlAND ($this->x >= ($this->lMargin + $chrwidth)))) {
  3734.                                 // print a void cell and go to next line
  3735.                                 $this->Cell($w$h''01);
  3736.                                 $linebreak true;
  3737.                                 if ($firstline{
  3738.                                     return ($this->UTF8ArrSubString($chars$j));
  3739.                                 }
  3740.                             else {
  3741.                                 // truncate the word because do not fit on column
  3742.                                 if ($firstline{
  3743.                                     $startx $this->x;
  3744.                                     $linew $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars$j$i)$this->tmprtl));
  3745.                                     if ($this->rtl{
  3746.                                         $this->endlinex = $startx $linew;
  3747.                                     else {
  3748.                                         $this->endlinex = $startx $linew;
  3749.                                     }
  3750.                                     $w $linew;
  3751.                                     $tmpcmargin $this->cMargin;
  3752.                                     if ($maxh == 0{
  3753.                                         $this->cMargin = 0;
  3754.                                     }
  3755.                                 }
  3756.                                 $this->Cell($w$h$this->UTF8ArrSubString($chars$j$i)01$align$fill$link$stretch);
  3757.                                 if ($firstline{
  3758.                                     $this->cMargin = $tmpcmargin;
  3759.                                     return ($this->UTF8ArrSubString($chars$i));
  3760.                                 }
  3761.                                 $j $i;
  3762.                                 --$i;
  3763.                             }    
  3764.                         else {
  3765.                             // word wrapping
  3766.                             if ($this->rtl AND (!$firstblock)) {
  3767.                                 $endspace 1;
  3768.                             else {
  3769.                                 $endspace 0;
  3770.                             }
  3771.                             if ($firstline{
  3772.                                 $startx $this->x;
  3773.                                 $linew $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars$j($sep $endspace))$this->tmprtl));
  3774.                                 if ($this->rtl{
  3775.                                     $this->endlinex = $startx $linew;
  3776.                                 else {
  3777.                                     $this->endlinex = $startx $linew;
  3778.                                 }
  3779.                                 $w $linew;
  3780.                                 $tmpcmargin $this->cMargin;
  3781.                                 if ($maxh == 0{
  3782.                                     $this->cMargin = 0;
  3783.                                 }
  3784.                             }
  3785.                             $this->Cell($w$h$this->UTF8ArrSubString($chars$j($sep $endspace))01$align$fill$link$stretch);
  3786.                             if ($firstline{
  3787.                                 $this->cMargin = $tmpcmargin;
  3788.                                 return ($this->UTF8ArrSubString($chars($sep $endspace)));
  3789.                             }
  3790.                             $i $sep;
  3791.                             $sep = -1;
  3792.                             $j ($i+1);
  3793.                         }
  3794.                         // account for margin changes
  3795.                         if ((($this->y + $this->lasth$this->PageBreakTriggerAND (!$this->InFooter)) {
  3796.                             // AcceptPageBreak() may be overriden on extended classed to include margin changes
  3797.                             $this->AcceptPageBreak();
  3798.                         }
  3799.                         $w $this->getRemainingWidth();
  3800.                         $wmax $w ($this->cMargin);
  3801.                         if ($linebreak{
  3802.                             $linebreak false;
  3803.                         else {
  3804.                             ++$nl;
  3805.                             $l 0;
  3806.                         }
  3807.                     }
  3808.                 }
  3809.                 ++$i;
  3810.             // end while i < nb
  3811.             // print last substring (if any)
  3812.             if ($l 0{
  3813.                 switch ($align{
  3814.                     case 'J':
  3815.                     case 'C'{
  3816.                         $w $w;
  3817.                         break;
  3818.                     }
  3819.                     case 'L'{
  3820.                         if ($this->rtl{
  3821.                             $w $w;
  3822.                         else {
  3823.                             $w $l;
  3824.                         }
  3825.                         break;
  3826.                     }
  3827.                     case 'R'{
  3828.                         if ($this->rtl{
  3829.                             $w $l;
  3830.                         else {
  3831.                             $w $w;
  3832.                         }
  3833.                         break;
  3834.                     }
  3835.                     default{
  3836.                         $w $l;
  3837.                         break;
  3838.                     }
  3839.                 }
  3840.                 if ($firstline{
  3841.                     $startx $this->x;
  3842.                     $linew $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars$j$nb)$this->tmprtl));
  3843.                     if ($this->rtl{
  3844.                         $this->endlinex = $startx $linew;
  3845.                     else {
  3846.                         $this->endlinex = $startx $linew;
  3847.                     }
  3848.                     $w $linew;
  3849.                     $tmpcmargin $this->cMargin;
  3850.                     if ($maxh == 0{
  3851.                         $this->cMargin = 0;
  3852.                     }
  3853.                 }
  3854.                 $this->Cell($w$h$this->UTF8ArrSubString($chars$j$nb)0$ln$align$fill$link$stretch);
  3855.                 if ($firstline{
  3856.                     $this->cMargin = $tmpcmargin;
  3857.                     return ($this->UTF8ArrSubString($chars$nb));
  3858.                 }
  3859.                 ++$nl;
  3860.             }
  3861.             if ($firstline{
  3862.                 return '';
  3863.             }
  3864.             return $nl;
  3865.         }
  3866.                 
  3867.         /**
  3868.         * Returns the remaining width between the current position and margins.
  3869.         * @return int Return the remaining width
  3870.         * @access protected
  3871.         */
  3872.         protected function getRemainingWidth({
  3873.             if ($this->rtl{
  3874.                 return ($this->x - $this->lMargin);
  3875.             else {
  3876.                 return ($this->w - $this->rMargin - $this->x);
  3877.             }
  3878.         }
  3879.  
  3880.      /**
  3881.         * Extract a slice of the $strarr array and return it as string.
  3882.         * @param string $strarr The input array of characters.
  3883.         * @param int $start the starting element of $strarr.
  3884.         * @param int $end first element that will not be returned.
  3885.         * @return Return part of a string
  3886.         */
  3887.         public function UTF8ArrSubString($strarr$start=''$end=''{
  3888.             if (strlen($start== 0{
  3889.                 $start 0;
  3890.             }
  3891.             if (strlen($end== 0{
  3892.                 $end count($strarr);
  3893.             }
  3894.             $string '';
  3895.             for ($i=$start$i $end++$i{
  3896.                 $string .= $this->unichr($strarr[$i]);
  3897.             }
  3898.             return $string;
  3899.         }
  3900.         
  3901.         /**
  3902.         * Returns the unicode caracter specified by UTF-8 code
  3903.         * @param int $c UTF-8 code
  3904.         * @return Returns the specified character.
  3905.         * @author Miguel Perez, Nicola Asuni
  3906.         * @since 2.3.000 (2008-03-05)
  3907.         */
  3908.         public function unichr($c{
  3909.             if (!$this->isunicode{
  3910.                 return chr($c);
  3911.             elseif ($c <= 0x7F{
  3912.                 // one byte
  3913.                 return chr($c);
  3914.             elseif ($c <= 0x7FF{
  3915.                 // two bytes
  3916.                 return chr(0xC0 $c >> 6).chr(0x80 $c 0x3F);
  3917.             elseif ($c <= 0xFFFF{
  3918.                 // three bytes
  3919.                 return chr(0xE0 $c >> 12).chr(0x80 $c >> 0x3F).chr(0x80 $c 0x3F);
  3920.             elseif ($c <= 0x10FFFF{
  3921.                 // four bytes
  3922.                 return chr(0xF0 $c >> 18).chr(0x80 $c >> 12 0x3F).chr(0x80 $c >> 0x3F).chr(0x80 $c 0x3F);
  3923.             else {
  3924.                 return '';
  3925.             }
  3926.         }
  3927.         
  3928.         /**
  3929.         * Puts an image in the page.
  3930.         * The upper-left corner must be given.
  3931.         * The dimensions can be specified in different ways:<ul>
  3932.         * <li>explicit width and height (expressed in user unit)</li>
  3933.         * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  3934.         * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  3935.         * Supported formats are JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;
  3936.         * The format can be specified explicitly or inferred from the file extension.<br />
  3937.         * It is possible to put a link on the image.<br />
  3938.         * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  3939.         * @param string $file Name of the file containing the image.
  3940.         * @param float $x Abscissa of the upper-left corner.
  3941.         * @param float $y Ordinate of the upper-left corner.
  3942.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  3943.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  3944.         * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  3945.         * @param mixed $link URL or identifier returned by AddLink().
  3946.         * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  3947.         * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  3948.         * @param int $dpi dot-per-inch resolution used on resize
  3949.         * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  3950.         * @param boolean $ismask true if this image is a mask, false otherwise
  3951.         * @param mixed $imgmask image object returned by this function or false
  3952.         * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3953.         * @return image information
  3954.         * @since 1.1
  3955.         */
  3956.         public function Image($file$x=''$y=''$w=0$h=0$type=''$link=''$align=''$resize=false$dpi=300$palign=''$ismask=false$imgmask=false$border=0{
  3957.             if ($x === ''{
  3958.                 $x $this->x;
  3959.             }
  3960.             if ($y === ''{
  3961.                 $y $this->y;
  3962.             }
  3963.             // get image size
  3964.             list($pixw$pixhgetimagesize($file);
  3965.             // calculate image width and height on document
  3966.             if (($w <= 0AND ($h <= 0)) {
  3967.                 // convert image size to document unit
  3968.                 $w $pixw ($this->imgscale * $this->k);
  3969.                 $h $pixh ($this->imgscale * $this->k);
  3970.             elseif ($w <= 0{
  3971.                 $w $h $pixw $pixh;
  3972.             elseif ($h <= 0{
  3973.                 $h $w $pixh $pixw;
  3974.             }
  3975.             // calculate new minimum dimensions in pixels
  3976.             $neww round($w $this->k * $dpi $this->dpi);
  3977.             $newh round($h $this->k * $dpi $this->dpi);
  3978.             // check if resize is necessary (resize is used only to reduce the image)
  3979.             if (($neww $newh>= ($pixw $pixh)) {
  3980.                 $resize false;
  3981.             }
  3982.             // check if image has been already added on document
  3983.             if (!in_array($file$this->imagekeys)) {
  3984.                 //First use of image, get info
  3985.                 if ($type == ''{
  3986.                     $fileinfo pathinfo($file);
  3987.                     if (isset($fileinfo['extension']AND (!empty($fileinfo['extension']))) {
  3988.                         $type $fileinfo['extension'];
  3989.                     else {
  3990.                         $this->Error('Image file has no extension and no type was specified: '.$file);
  3991.                     }
  3992.                 }
  3993.                 $type strtolower($type);
  3994.                 if ($type == 'jpg'{
  3995.                     $type 'jpeg';
  3996.                 }
  3997.                 $mqr get_magic_quotes_runtime();
  3998.                 set_magic_quotes_runtime(0);
  3999.                 // Specific image handlers
  4000.                 $mtd '_parse'.$type;
  4001.                 // GD image handler function
  4002.                 $gdfunction 'imagecreatefrom'.$type;
  4003.                 $info false;
  4004.                 if ((method_exists($this$mtd)) AND (!($resize AND function_exists($gdfunction)))) {
  4005.                     // TCPDF image functions
  4006.                     $info $this->$mtd($file);
  4007.                     if ($info == 'pngalpha'{
  4008.                         return $this->ImagePngAlpha($file$x$y$w$h'PNG'$link$align$resize$dpi$palign);
  4009.                     }
  4010.                 
  4011.                 if (!$info{
  4012.                     if (function_exists($gdfunction)) {
  4013.                         // GD library
  4014.                         $img $gdfunction($file);
  4015.                         if ($resize{
  4016.                             $imgr imagecreatetruecolor($neww$newh);
  4017.                             imagecopyresampled($imgr$img0000$neww$newh$pixw$pixh)
  4018.                             $info $this->_toJPEG($imgr);
  4019.                         else {
  4020.                             $info $this->_toJPEG($img);
  4021.                         }
  4022.                     elseif (extension_loaded('imagick')) {
  4023.                         // ImageMagick library
  4024.                         $img new Imagick();
  4025.                         $img->readImage($file);
  4026.                         if ($resize{
  4027.                             $img->resizeImage($neww$newh101false);
  4028.                         }
  4029.                         $img->setCompressionQuality($this->jpeg_quality);
  4030.                         $img->setImageFormat('jpeg');
  4031.                         $tempname tempnam(K_PATH_CACHE'jpg_');
  4032.                         $img->writeImage($tempname);
  4033.                         $info $this->_parsejpeg($tempname);
  4034.                         unlink($tempname);
  4035.                         $img->destroy();
  4036.                     else {
  4037.                         return;
  4038.                     }
  4039.                 }
  4040.                 if ($info === false{
  4041.                     //If false, we cannot process image
  4042.                     return;
  4043.                 }
  4044.                 set_magic_quotes_runtime($mqr);
  4045.                 if ($ismask{
  4046.                     // force grayscale
  4047.                     $info['cs''DeviceGray'
  4048.                 }
  4049.                 $info['i'$this->numimages + 1;
  4050.                 if ($imgmask !== false{
  4051.                     $info['masked'$imgmask;
  4052.                 }
  4053.                 // add image to document
  4054.                 $this->setImageBuffer($file$info);
  4055.             else {
  4056.                 $info $this->getImageBuffer($file);
  4057.             }
  4058.             // Check whether we need a new page first as this does not fit
  4059.             if ((($y $h$this->PageBreakTriggerAND (!$this->InFooterAND $this->AcceptPageBreak()) {
  4060.                 // Automatic page break
  4061.                 $this->AddPage($this->CurOrientation);
  4062.                 // Reset Y coordinate to the top of next page
  4063.                 $y $this->GetY($this->cMargin;
  4064.             }
  4065.             // set bottomcoordinates
  4066.             $this->img_rb_y = $y $h;
  4067.             // set alignment
  4068.             if ($this->rtl{
  4069.                 if ($palign == 'L'{
  4070.                     $ximg $this->lMargin;
  4071.                     // set right side coordinate
  4072.                     $this->img_rb_x = $ximg $w;
  4073.                 elseif ($palign == 'C'{
  4074.                     $ximg ($this->w - $x $w2;
  4075.                     // set right side coordinate
  4076.                     $this->img_rb_x = $ximg $w;
  4077.                 else {
  4078.                     $ximg $this->w - $x $w;
  4079.                     // set left side coordinate
  4080.                     $this->img_rb_x = $ximg;
  4081.                 }
  4082.             else {
  4083.                 if ($palign == 'R'{
  4084.                     $ximg $this->w - $this->rMargin - $w;
  4085.                     // set left side coordinate
  4086.                     $this->img_rb_x = $ximg;
  4087.                 elseif ($palign == 'C'{
  4088.                     $ximg ($this->w - $x $w2;
  4089.                     // set right side coordinate
  4090.                     $this->img_rb_x = $ximg $w;
  4091.                 else {
  4092.                     $ximg $x;
  4093.                     // set right side coordinate
  4094.                     $this->img_rb_x = $ximg $w;
  4095.                 }
  4096.             }
  4097.             if ($ismask{
  4098.                 // embed hidden, ouside the canvas
  4099.                 $xkimg ($this->pagedim[$this->page]['w'10);
  4100.             else {
  4101.                 $xkimg $ximg $this->k;
  4102.             }
  4103.             $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q'($w $this->k)($h $this->k)$xkimg(($this->h - ($y $h)) $this->k)$info['i']));
  4104.             if (!empty($border)) {
  4105.                 $bx $x;
  4106.                 $by $y;
  4107.                 $this->x = $x;
  4108.                 $this->y = $y;
  4109.                 $this->Cell($w$h''$border0''0''0);
  4110.                 $this->x = $bx;
  4111.                 $this->y = $by;
  4112.             }
  4113.             if ($link{
  4114.                 $this->Link($ximg$y$w$h$link0);
  4115.             }
  4116.             // set pointer to align the successive text/objects
  4117.             switch($align{
  4118.                 case 'T'{
  4119.                     $this->y = $y;
  4120.                     $this->x = $this->img_rb_x;
  4121.                     break;
  4122.                 }
  4123.                 case 'M'{
  4124.                     $this->y = $y round($h/2);
  4125.                     $this->x = $this->img_rb_x;
  4126.                     break;
  4127.                 }
  4128.                 case 'B'{
  4129.                     $this->y = $this->img_rb_y;
  4130.                     $this->x = $this->img_rb_x;
  4131.                     break;
  4132.                 }
  4133.                 case 'N'{
  4134.                     $this->SetY($this->img_rb_y);
  4135.                     break;
  4136.                 }
  4137.                 default:{
  4138.                     break;
  4139.                 }
  4140.             }
  4141.             $this->endlinex = $this->img_rb_x;
  4142.             return $info['i'];
  4143.         }
  4144.                 
  4145.         /**
  4146.         * Convert the loaded php image to a JPEG and then return a structure for the PDF creator.
  4147.         * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  4148.         * @param string $file Image file name.
  4149.         * @param image $image Image object.
  4150.         *  return image JPEG image object.
  4151.         * @access protected
  4152.         */
  4153.         protected function _toJPEG($image{
  4154.             $tempname tempnam(K_PATH_CACHE'jpg_');
  4155.             imagejpeg($image$tempname$this->jpeg_quality);
  4156.             imagedestroy($image);
  4157.             $retvars $this->_parsejpeg($tempname);
  4158.             // tidy up by removing temporary image
  4159.             unlink($tempname);
  4160.             return $retvars;
  4161.         }
  4162.         
  4163.         /**
  4164.         * Extract info from a JPEG file without using the GD library.
  4165.         * @param string $file image file to parse
  4166.         * @return array structure containing the image data
  4167.         * @access protected
  4168.         */
  4169.         protected function _parsejpeg($file{
  4170.             $a getimagesize($file);
  4171.             if (empty($a)) {
  4172.                 $this->Error('Missing or incorrect image file: '.$file);
  4173.             }
  4174.             if ($a[2!= 2{
  4175.                 $this->Error('Not a JPEG file: '.$file);
  4176.             }
  4177.             if ((!isset($a['channels'])) OR ($a['channels'== 3)) {
  4178.                 $colspace 'DeviceRGB';
  4179.             elseif ($a['channels'== 4{
  4180.                 $colspace 'DeviceCMYK';
  4181.             else {
  4182.                 $colspace 'DeviceGray';
  4183.             }
  4184.             $bpc = isset($a['bits']$a['bits'8;
  4185.             $data file_get_contents($file);
  4186.             return array('w' => $a[0]'h' => $a[1]'cs' => $colspace'bpc' => $bpc'f' => 'DCTDecode''data' => $data);
  4187.         }
  4188.  
  4189.         /**
  4190.         * Extract info from a PNG file without using the GD library.
  4191.         * @param string $file image file to parse
  4192.         * @return array structure containing the image data
  4193.         * @access protected
  4194.         */
  4195.         protected function _parsepng($file{
  4196.             $f fopen($file,'rb');
  4197.             if (empty($f)) {
  4198.                 $this->Error('Can\'t open image file: '.$file);
  4199.             }
  4200.             //Check signature
  4201.             if (fread($f,8!= chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  4202.                 $this->Error('Not a PNG file: '.$file);
  4203.             }
  4204.             //Read header chunk
  4205.             fread($f,4);
  4206.             if (fread($f,4!= 'IHDR'{
  4207.                 $this->Error('Incorrect PNG file: '.$file);
  4208.             }
  4209.             $w $this->_freadint($f);
  4210.             $h $this->_freadint($f);
  4211.             $bpc ord(fread($f,1));
  4212.             if ($bpc 8{
  4213.                 //$this->Error('16-bit depth not supported: '.$file);
  4214.                 fclose($f);
  4215.                 return false;
  4216.             }
  4217.             $ct ord(fread($f,1));
  4218.             if ($ct == 0{
  4219.                 $colspace 'DeviceGray';
  4220.             elseif ($ct == 2{
  4221.                 $colspace 'DeviceRGB';
  4222.             elseif ($ct == 3{
  4223.                 $colspace 'Indexed';
  4224.             else {
  4225.                 // alpha channel
  4226.                 fclose($f);
  4227.                 return 'pngalpha';
  4228.             }
  4229.             if (ord(fread($f,1)) != 0{
  4230.                 //$this->Error('Unknown compression method: '.$file);
  4231.                 fclose($f);
  4232.                 return false;
  4233.             }
  4234.             if (ord(fread($f,1)) != 0{
  4235.                 //$this->Error('Unknown filter method: '.$file);
  4236.                 fclose($f);
  4237.                 return false;
  4238.             }
  4239.             if (ord(fread($f,1)) != 0{
  4240.                 //$this->Error('Interlacing not supported: '.$file);
  4241.                 fclose($f);
  4242.                 return false;
  4243.             }
  4244.             fread($f,4);
  4245.             $parms '/DecodeParms <</Predictor 15 /Colors '.($ct==1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  4246.             //Scan chunks looking for palette, transparency and image data
  4247.             $pal '';
  4248.             $trns '';
  4249.             $data '';
  4250.             do {
  4251.                 $n $this->_freadint($f);
  4252.                 $type fread($f4);
  4253.                 if ($type == 'PLTE'{
  4254.                     //Read palette
  4255.                     $pal fread($f$n);
  4256.                     fread($f4);
  4257.                 elseif ($type == 'tRNS'{
  4258.                     //Read transparency info
  4259.                     $t fread($f$n);
  4260.                     if ($ct == 0{
  4261.                         $trns array(ord(substr($t11)));
  4262.                     elseif ($ct == 2{
  4263.                         $trns array(ord(substr($t11))ord(substr($t31))ord(substr($t51)));
  4264.                     else {
  4265.                         $pos strpos($tchr(0));
  4266.                         if ($pos !== false{
  4267.                             $trns array($pos);
  4268.                         }
  4269.                     }
  4270.                     fread($f4);
  4271.                 elseif ($type == 'IDAT'{
  4272.                     //Read image data block
  4273.                     $data .= fread($f$n);
  4274.                     fread($f4);
  4275.                 elseif ($type == 'IEND'{
  4276.                     break;
  4277.                 else {
  4278.                     fread($f$n 4);
  4279.                 }
  4280.             while ($n);
  4281.             if (($colspace == 'Indexed'AND (empty($pal))) {
  4282.                 //$this->Error('Missing palette in '.$file);
  4283.                 fclose($f);
  4284.                 return false;
  4285.             }
  4286.             fclose($f);
  4287.             return array('w' => $w'h' => $h'cs' => $colspace'bpc' => $bpc'f' => 'FlateDecode''parms' => $parms'pal' => $pal'trns' => $trns'data' => $data);
  4288.         }
  4289.         
  4290.         /**
  4291.         * Extract info from a PNG image with alpha channel using the GD library.
  4292.         * @param string $file Name of the file containing the image.
  4293.         * @param float $x Abscissa of the upper-left corner.
  4294.         * @param float $y Ordinate of the upper-left corner.
  4295.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4296.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4297.         * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  4298.         * @param mixed $link URL or identifier returned by AddLink().
  4299.         * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  4300.         * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  4301.         * @param int $dpi dot-per-inch resolution used on resize
  4302.         * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  4303.         * @author Valentin Schmidt, Nicola Asuni
  4304.         * @since 4.3.007 (2008-12-04)
  4305.         * @see Image()
  4306.         */
  4307.         protected function ImagePngAlpha($file$x=''$y=''$w=0$h=0$type=''$link=''$align=''$resize=false$dpi=300$palign=''{
  4308.             // get image size
  4309.             list($wpx$hpxgetimagesize($file);
  4310.             // generate images
  4311.             $img imagecreatefrompng($file);
  4312.             $imgalpha imagecreate($wpx$hpx);
  4313.             // generate gray scale pallete
  4314.             for($c 0$c 256++$c{
  4315.                 ImageColorAllocate($imgalpha$c$c$c);
  4316.             }
  4317.             // extract alpha channel
  4318.             for ($xpx 0$xpx $wpx++$xpx{
  4319.                 for ($ypx 0$ypx $hpx++$ypx{
  4320.                     $colorindex imagecolorat($img$xpx$ypx);
  4321.                     $col imagecolorsforindex($img$colorindex);
  4322.                     imagesetpixel($imgalpha$xpx$ypx$this->getGDgamma((127 $col['alpha']255 127));
  4323.                 }
  4324.             }
  4325.             // create temp alpha file
  4326.             $tempfile_alpha tempnam(K_PATH_CACHE'mska_');
  4327.             imagepng($imgalpha$tempfile_alpha);
  4328.             imagedestroy($imgalpha);
  4329.             // extract image without alpha channel
  4330.             $imgplain imagecreatetruecolor($wpx$hpx);
  4331.             imagecopy($imgplain$img0000$wpx$hpx);
  4332.             // create temp image file
  4333.             $tempfile_plain tempnam(K_PATH_CACHE'mskp_');
  4334.             imagepng($imgplain$tempfile_plain);
  4335.             imagedestroy($imgplain);
  4336.             // embed mask image
  4337.             $imgmask $this->Image($tempfile_alpha$x$y$w$h'PNG'''''$resize$dpi''truefalse);
  4338.             // embed image, masked with previously embedded mask
  4339.             $this->Image($tempfile_plain$x$y$w$h$type$link$align$resize$dpi$palignfalse$imgmask);
  4340.             // remove temp files
  4341.             unlink($tempfile_alpha);
  4342.             unlink($tempfile_plain);
  4343.         }
  4344.  
  4345.         /**
  4346.         * Correct the gamma value to be used with GD library
  4347.         * @param float $v the gamma value to be corrected
  4348.         * @since 4.3.007 (2008-12-04)
  4349.         */
  4350.         protected function getGDgamma($v{
  4351.             return (pow(($v 255)2.2255);
  4352.         
  4353.         
  4354.         /**
  4355.         * Performs a line break.
  4356.         * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  4357.         * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  4358.         * @param boolean $cell if true add a cMargin to the x coordinate
  4359.         * @since 1.0
  4360.         * @see Cell()
  4361.         */
  4362.         public function Ln($h=''$cell=false{
  4363.             //Line feed; default value is last cell height
  4364.             if ($cell{
  4365.                 $cellmargin $this->cMargin;
  4366.             else {
  4367.                 $cellmargin 0;
  4368.             }
  4369.             if ($this->rtl{
  4370.                 $this->x = $this->w - $this->rMargin - $cellmargin;
  4371.             else {
  4372.                 $this->x = $this->lMargin + $cellmargin;
  4373.             }
  4374.             if (is_string($h)) {
  4375.                 $this->y += $this->lasth;
  4376.             else {
  4377.                 $this->y += $h;
  4378.             }
  4379.             $this->newline = true;
  4380.         }
  4381.  
  4382.         /**
  4383.         * Returns the relative X value of current position.
  4384.         * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  4385.         * @return float 
  4386.         * @since 1.2
  4387.         * @see SetX(), GetY(), SetY()
  4388.         */
  4389.         public function GetX({
  4390.             //Get x position
  4391.             if ($this->rtl{
  4392.                 return ($this->w - $this->x);
  4393.             else {
  4394.                 return $this->x;
  4395.             }
  4396.         }
  4397.         
  4398.         /**
  4399.         * Returns the absolute X value of current position.
  4400.         * @return float 
  4401.         * @since 1.2
  4402.         * @see SetX(), GetY(), SetY()
  4403.         */
  4404.         public function GetAbsX({
  4405.             return $this->x;
  4406.         }
  4407.         
  4408.         /**
  4409.         * Returns the ordinate of the current position.
  4410.         * @return float 
  4411.         * @since 1.0
  4412.         * @see SetY(), GetX(), SetX()
  4413.         */
  4414.         public function GetY({
  4415.             //Get y position
  4416.             return $this->y;
  4417.         }
  4418.         
  4419.         /**
  4420.         * Defines the abscissa of the current position.
  4421.         * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  4422.         * @param float $x The value of the abscissa.
  4423.         * @since 1.2
  4424.         * @see GetX(), GetY(), SetY(), SetXY()
  4425.         */
  4426.         public function SetX($x{
  4427.             //Set x position
  4428.             if ($this->rtl{
  4429.                 if ($x >= 0{
  4430.                     $this->x = $this->w - $x;
  4431.                 else {
  4432.                     $this->x = abs($x);
  4433.                 }
  4434.             else {
  4435.                 if ($x >= 0{
  4436.                     $this->x = $x;
  4437.                 else {
  4438.                     $this->x = $this->w + $x;
  4439.                 }
  4440.             }
  4441.             if ($this->x < 0{
  4442.                 $this->x = 0;
  4443.             }
  4444.             if ($this->x > $this->w{
  4445.                 $this->x = $this->w;
  4446.             }
  4447.         }
  4448.         
  4449.         /**
  4450.         * Moves the current abscissa back to the left margin and sets the ordinate.
  4451.         * If the passed value is negative, it is relative to the bottom of the page.
  4452.         * @param float $y The value of the ordinate.
  4453.         * @param bool $resetx if true (default) reset the X position.
  4454.         * @since 1.0
  4455.         * @see GetX(), GetY(), SetY(), SetXY()
  4456.         */
  4457.         public function SetY($y$resetx=true{
  4458.             if ($resetx{
  4459.                 //reset x
  4460.                 if ($this->rtl{
  4461.                     $this->x = $this->w - $this->rMargin;
  4462.                 else {
  4463.                     $this->x = $this->lMargin;
  4464.                 }
  4465.             }
  4466.             if ($y >= 0{
  4467.                 $this->y = $y;
  4468.             else {
  4469.                 $this->y = $this->h + $y;
  4470.             }
  4471.             if ($this->y < 0{
  4472.                 $this->y = 0;
  4473.             }
  4474.             if ($this->y > $this->h{
  4475.                 $this->y = $this->h;
  4476.             }
  4477.         }
  4478.         
  4479.         /**
  4480.         * Defines the abscissa and ordinate of the current position.
  4481.         * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  4482.         * @param float $x The value of the abscissa
  4483.         * @param float $y The value of the ordinate
  4484.         * @since 1.2
  4485.         * @see SetX(), SetY()
  4486.         */
  4487.         public function SetXY($x$y{
  4488.             //Set x and y positions
  4489.             $this->SetY($y);
  4490.             $this->SetX($x);
  4491.         }
  4492.  
  4493.         /**
  4494.         * Send the document to a given destination: string, local file or browser.
  4495.         * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  4496.         * The method first calls Close() if necessary to terminate the document.
  4497.         * @param string $name The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  4498.         * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li></ul>
  4499.         * @since 1.0
  4500.         * @see Close()
  4501.         */
  4502.         public function Output($name='doc.pdf'$dest='I'{
  4503.             //Output PDF to some destination
  4504.             //Finish document if necessary
  4505.             if ($this->state < 3{
  4506.                 $this->Close();
  4507.             }
  4508.             //Normalize parameters
  4509.             if (is_bool($dest)) {
  4510.                 $dest $dest 'D' 'F';
  4511.             }
  4512.             $dest strtoupper($dest);
  4513.             if ($dest != 'F'{
  4514.                 $name preg_replace('/[\s]+/''_'$name);
  4515.                 $name preg_replace('/[^a-zA-Z0-9_\.-]/'''$name);
  4516.             }
  4517.             switch($dest{
  4518.                 case 'I'{
  4519.                     //Send to standard output
  4520.                     if (ob_get_contents()) {
  4521.                         $this->Error('Some data has already been output, can\'t send PDF file');
  4522.                     }
  4523.                     if (php_sapi_name(!= 'cli'{
  4524.                         //We send to a browser
  4525.                         header('Content-Type: application/pdf');
  4526.                         if (headers_sent()) {
  4527.                             $this->Error('Some data has already been output to browser, can\'t send PDF file');
  4528.                         }
  4529.                         header('Cache-Control: public, must-revalidate, max-age=0')// HTTP/1.1
  4530.                         header('Pragma: public');
  4531.                         header('Expires: Sat, 26 Jul 1997 05:00:00 GMT')// Date in the past
  4532.                         header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');    
  4533.                         header('Content-Length: '.$this->bufferlen);
  4534.                         header('Content-Disposition: inline; filename="'.basename($name).'";');
  4535.                     }
  4536.                     echo $this->getBuffer();
  4537.                     break;
  4538.                 }
  4539.                 case 'D'{
  4540.                     //Download file
  4541.                     if (ob_get_contents()) {
  4542.                         $this->Error('Some data has already been output, can\'t send PDF file');
  4543.                     }
  4544.                     header('Content-Description: File Transfer');
  4545.                     if (headers_sent()) {
  4546.                         $this->Error('Some data has already been output to browser, can\'t send PDF file');
  4547.                     }
  4548.                     header('Cache-Control: public, must-revalidate, max-age=0')// HTTP/1.1
  4549.                     header('Pragma: public');
  4550.                     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT')// Date in the past
  4551.                     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  4552.                     // force download dialog
  4553.                     header('Content-Type: application/force-download');
  4554.                     header('Content-Type: application/octet-stream'false);
  4555.                     header('Content-Type: application/download'false);
  4556.                     header('Content-Type: application/pdf'false);
  4557.                     // use the Content-Disposition header to supply a recommended filename
  4558.                     header('Content-Disposition: attachment; filename="'.basename($name).'";');
  4559.                     header('Content-Transfer-Encoding: binary');
  4560.                     header('Content-Length: '.$this->bufferlen);
  4561.                     echo $this->getBuffer();
  4562.                     break;
  4563.                 }
  4564.                 case 'F'{
  4565.                     //Save to local file
  4566.                     if ($this->diskcache{
  4567.                         copy($this->buffer$name);
  4568.                     else {
  4569.                         $f fopen($name'wb');
  4570.                         if (!$f{
  4571.                             $this->Error('Unable to create output file: '.$name);
  4572.                         }
  4573.                         fwrite($f$this->getBuffer()$this->bufferlen);
  4574.                         fclose($f);
  4575.                     }
  4576.                     break;
  4577.                 }
  4578.                 case 'S'{
  4579.                     //Return as a string
  4580.                     return $this->getBuffer();
  4581.                 }
  4582.                 default{
  4583.                     $this->Error('Incorrect output destination: '.$dest);
  4584.                 }
  4585.             }
  4586.             if ($this->diskcache{
  4587.                 unlink($this->buffer);
  4588.             }
  4589.             return '';
  4590.         }
  4591.         
  4592.         /**
  4593.         * Check for locale-related bug
  4594.         * @access protected
  4595.         */
  4596.         protected function _dochecks({
  4597.             //Check for locale-related bug
  4598.             if (1.1 == 1{
  4599.                 $this->Error('Don\'t alter the locale before including class file');
  4600.             }
  4601.             //Check for decimal separator
  4602.             if (sprintf('%.1f'1.0!= '1.0'{
  4603.                 setlocale(LC_NUMERIC'C');
  4604.             }
  4605.         }
  4606.  
  4607.         /**
  4608.         * Return fonts path
  4609.         * @return string 
  4610.         * @access protected
  4611.         */
  4612.         protected function _getfontpath({
  4613.             if (!defined('K_PATH_FONTS'AND is_dir(dirname(__FILE__).'/fonts')) {
  4614.                 define('K_PATH_FONTS'dirname(__FILE__).'/fonts/');
  4615.             }
  4616.             return defined('K_PATH_FONTS'K_PATH_FONTS '';
  4617.         }
  4618.         
  4619.         /**
  4620.         * Output pages.
  4621.         * @access protected
  4622.         */
  4623.         protected function _putpages({
  4624.             $nb $this->numpages;
  4625.             if (!empty($this->AliasNbPages)) {
  4626.                 $nbs $this->formatPageNumber($nb);
  4627.                 $nbu $this->UTF8ToUTF16BE($nbsfalse)// replacement for unicode font
  4628.                 $alias_a $this->_escape($this->AliasNbPages);
  4629.                 $alias_au $this->_escape('{'.$this->AliasNbPages.'}');
  4630.                 if ($this->isunicode{
  4631.                     $alias_b $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  4632.                     $alias_bu $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNbPages.'}'));
  4633.                     $alias_c $this->_escape($this->utf8StrRev($this->AliasNbPagesfalse$this->tmprtl));
  4634.                     $alias_cu $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages.'}'false$this->tmprtl));
  4635.                 }
  4636.             }
  4637.             if (!empty($this->AliasNumPage)) {
  4638.                 $alias_pa $this->_escape($this->AliasNumPage);
  4639.                 $alias_pau $this->_escape('{'.$this->AliasNumPage.'}');
  4640.                 if ($this->isunicode{
  4641.                     $alias_pb $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  4642.                     $alias_pbu $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNumPage.'}'));
  4643.                     $alias_pc $this->_escape($this->utf8StrRev($this->AliasNumPagefalse$this->tmprtl));
  4644.                     $alias_pcu $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage.'}'false$this->tmprtl));
  4645.                 }
  4646.             }
  4647.             $pagegroupnum 0;
  4648.             $filter ($this->compress'/Filter /FlateDecode ' '';
  4649.             for($n=1$n <= $nb++$n{
  4650.                 $temppage $this->getPageBuffer($n);
  4651.                 if (!empty($this->pagegroups)) {
  4652.                     if(isset($this->newpagegroup[$n])) {
  4653.                         $pagegroupnum 0;
  4654.                     }
  4655.                     ++$pagegroupnum;
  4656.                     foreach ($this->pagegroups as $k => $v{
  4657.                         // replace total pages group numbers
  4658.                         $vs $this->formatPageNumber($v);
  4659.                         $vu $this->UTF8ToUTF16BE($vsfalse);
  4660.                         $alias_ga $this->_escape($k);
  4661.                         $alias_gau $this->_escape('{'.$k.'}');
  4662.                         if ($this->isunicode{
  4663.                             $alias_gb $this->_escape($this->UTF8ToLatin1($k));
  4664.                             $alias_gbu $this->_escape($this->UTF8ToLatin1('{'.$k.'}'));
  4665.                             $alias_gc $this->_escape($this->utf8StrRev($kfalse$this->tmprtl));
  4666.                             $alias_gcu $this->_escape($this->utf8StrRev('{'.$k.'}'false$this->tmprtl));
  4667.                         }
  4668.                         $temppage str_replace($alias_gau$vu$temppage);
  4669.                         if ($this->isunicode{
  4670.                             $temppage str_replace($alias_gbu$vu$temppage);
  4671.                             $temppage str_replace($alias_gcu$vu$temppage);
  4672.                             $temppage str_replace($alias_gb$vs$temppage);
  4673.                             $temppage str_replace($alias_gc$vs$temppage);
  4674.                         }
  4675.                         $temppage str_replace($alias_ga$vs$temppage);
  4676.                         // replace page group numbers
  4677.                         $pvs $this->formatPageNumber($pagegroupnum);
  4678.                         $pvu $this->UTF8ToUTF16BE($pvsfalse);
  4679.                         $pk str_replace('{nb''{pnb'$k);
  4680.                         $alias_pga $this->_escape($pk);
  4681.                         $alias_pgau $this->_escape('{'.$pk.'}');
  4682.                         if ($this->isunicode{
  4683.                             $alias_pgb $this->_escape($this->UTF8ToLatin1($pk));
  4684.                             $alias_pgbu $this->_escape($this->UTF8ToLatin1('{'.$pk.'}'));
  4685.                             $alias_pgc $this->_escape($this->utf8StrRev($pkfalse$this->tmprtl));
  4686.                             $alias_pgcu $this->_escape($this->utf8StrRev('{'.$pk.'}'false$this->tmprtl));
  4687.                         }
  4688.                         $temppage str_replace($alias_pgau$pvu$temppage);
  4689.                         if ($this->isunicode{
  4690.                             $temppage str_replace($alias_pgbu$pvu$temppage);
  4691.                             $temppage str_replace($alias_pgcu$pvu$temppage);
  4692.                             $temppage str_replace($alias_pgb$pvs$temppage);
  4693.                             $temppage str_replace($alias_pgc$pvs$temppage);
  4694.                         }
  4695.                         $temppage str_replace($alias_pga$pvs$temppage);
  4696.                     }
  4697.                 }
  4698.                 if (!empty($this->AliasNbPages)) {
  4699.                     // replace total pages number
  4700.                     $temppage str_replace($alias_au$nbu$temppage);
  4701.                     if ($this->isunicode{
  4702.                         $temppage str_replace($alias_bu$nbu$temppage);
  4703.                         $temppage str_replace($alias_cu$nbu$temppage);
  4704.                         $temppage str_replace($alias_b$nbs$temppage);
  4705.                         $temppage str_replace($alias_c$nbs$temppage);
  4706.                     }
  4707.                     $temppage str_replace($alias_a$nbs$temppage);
  4708.                 }
  4709.                 if (!empty($this->AliasNumPage)) {
  4710.                     // replace page number
  4711.                     $pnbs $this->formatPageNumber($n);
  4712.                     $pnbu $this->UTF8ToUTF16BE($pnbsfalse)// replacement for unicode font
  4713.                     $temppage str_replace($alias_pau$pnbu$temppage);
  4714.                     if ($this->isunicode{
  4715.                         $temppage str_replace($alias_pbu$pnbu$temppage);
  4716.                         $temppage str_replace($alias_pcu$pnbu$temppage);
  4717.                         $temppage str_replace($alias_pb$pnbs$temppage);
  4718.                         $temppage str_replace($alias_pc$pnbs$temppage);
  4719.                     }
  4720.                     $temppage str_replace($alias_pa$pnbs$temppage);
  4721.                 }
  4722.                 $temppage str_replace($this->epsmarker''$temppage);
  4723.                 //$this->setPageBuffer($n, $temppage);
  4724.                 //Page
  4725.                 $this->_newobj();
  4726.                 $this->_out('<</Type /Page');
  4727.                 $this->_out('/Parent 1 0 R');
  4728.                 $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]'$this->pagedim[$n]['w']$this->pagedim[$n]['h']));
  4729.                 $this->_out('/Resources 2 0 R');
  4730.                 $this->_putannots($n);
  4731.                 $this->_out('/Contents '.($this->n + 1).' 0 R>>');
  4732.                 $this->_out('endobj');
  4733.                 //Page content
  4734.                 $p ($this->compressgzcompress($temppage$temppage;
  4735.                 $this->_newobj();
  4736.                 $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  4737.                 $this->_putstream($p);
  4738.                 $this->_out('endobj');
  4739.                 if ($this->diskcache{
  4740.                     // remove temporary files
  4741.                     unlink($this->pages[$n]);
  4742.                 }
  4743.             }
  4744.             //Pages root
  4745.             $this->offsets[1$this->bufferlen;
  4746.             $this->_out('1 0 obj');
  4747.             $this->_out('<</Type /Pages');
  4748.             $kids='/Kids [';
  4749.             for($i=0$i $nb++$i{
  4750.                 $kids .= (($i)).' 0 R ';
  4751.             }
  4752.             $this->_out($kids.']');
  4753.             $this->_out('/Count '.$nb);
  4754.             //$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$this->pagedim[0]['w'],$this->pagedim[0]['h']));
  4755.             $this->_out('>>');
  4756.             $this->_out('endobj');
  4757.         }
  4758.  
  4759.         /**
  4760.         * Output Page Annotations.
  4761.         * !!! THIS FUNCTION IS NOT YET COMPLETED !!!
  4762.         * See section 8.4 of PDF reference.
  4763.         * @param int $n page number
  4764.         * @access protected
  4765.         * @author Nicola Asuni
  4766.         * @since 4.0.018 (2008-08-06)
  4767.         */
  4768.         protected function _putannots($n{
  4769.             if (isset($this->PageAnnots[$n])) {
  4770.                 $annots '/Annots [';
  4771.                 foreach ($this->PageAnnots[$nas $key => $pl{
  4772.                     $pl['opt'array_change_key_case($pl['opt']CASE_LOWER);
  4773.                     $a $pl['x'$this->k;
  4774.                     $b $this->pagedim[$n]['h'($pl['y']  $this->k);
  4775.                     $c $pl['w'$this->k;
  4776.                     $d $pl['h'$this->k;
  4777.                     $rect sprintf('%.2f %.2f %.2f %.2f'$a$b$a+$c$b-$d);
  4778.                     $annots .= "\n";
  4779.                     $annots .= '<</Type /Annot';
  4780.                     $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  4781.                     $annots .= ' /Rect ['.$rect.']';
  4782.                     $annots .= ' /Contents '.$this->_textstring($pl['txt']);
  4783.                     //$annots .= ' /P ';
  4784.                     $annots .= ' /NM '.$this->_textstring(sprintf('%04u-%04u'$n$key));
  4785.                     $annots .= ' /M '.$this->_datastring('D:'.date('YmdHis'));
  4786.                     if (isset($pl['opt']['f'])) {
  4787.                         $val 0;
  4788.                         if (is_array($pl['opt']['f'])) {
  4789.                             foreach ($pl['opt']['f'as $f{
  4790.                                 switch (strtolower($f)) {
  4791.                                     case 'invisible'{
  4792.                                         $val += << 0;
  4793.                                         break;
  4794.                                     }
  4795.                                     case 'hidden'{
  4796.                                         $val += << 1;
  4797.                                         break;
  4798.                                     }
  4799.                                     case 'print'{
  4800.                                         $val += << 2;
  4801.                                         break;
  4802.                                     }
  4803.                                     case 'nozoom'{
  4804.                                         $val += << 3;
  4805.                                         break;
  4806.                                     }
  4807.                                     case 'norotate'{
  4808.                                         $val += << 4;
  4809.                                         break;
  4810.                                     }
  4811.                                     case 'noview'{
  4812.                                         $val += << 5;
  4813.                                         break;
  4814.                                     }
  4815.                                     case 'readonly'{
  4816.                                         $val += << 6;
  4817.                                         break;
  4818.                                     }
  4819.                                     case 'locked'{
  4820.                                         $val += << 8;
  4821.                                         break;
  4822.                                     }
  4823.                                     case 'togglenoview'{
  4824.                                         $val += << 9;
  4825.                                         break;
  4826.                                     }
  4827.                                     case 'lockedcontents'{
  4828.                                         $val += << 10;
  4829.                                         break;
  4830.                                     }
  4831.                                     default{
  4832.                                         break;
  4833.                                     }
  4834.                                 }
  4835.                             }
  4836.                         }
  4837.                         $annots .= ' /F '.intval($val);
  4838.                     }
  4839.                     //$annots .= ' /AP ';
  4840.                     //$annots .= ' /AS ';
  4841.                     $annots .= ' /Border [';
  4842.                     if (isset($pl['opt']['border']AND (count($pl['opt']['border']>= 3)) {
  4843.                         $annots .= intval($pl['opt']['border'][0]).' ';
  4844.                         $annots .= intval($pl['opt']['border'][1]).' ';
  4845.                         $annots .= intval($pl['opt']['border'][2]);
  4846.                         if (isset($pl['opt']['border'][3]AND is_array($pl['opt']['border'][3])) {
  4847.                             $annots .= ' [';
  4848.                             foreach ($pl['opt']['border'][3as $dash{
  4849.                                 $annots .= intval($dash).' ';
  4850.                             }
  4851.                             $annots .= ']';
  4852.                         }
  4853.                     else {
  4854.                         $annots .= '0 0 0';
  4855.                     }
  4856.                     $annots .= ']';
  4857.                     if (isset($pl['opt']['bs']AND (is_array($pl['opt']['bs']))) {
  4858.                         $annots .= ' /BS <<Type /Border';
  4859.                         if (isset($pl['opt']['bs']['w'])) {
  4860.                             $annots .= ' /W '.sprintf("%.4f"floatval($pl['opt']['bs']['w']));
  4861.                         }
  4862.                         $bstyles array('S''D''B''I''U');
  4863.                         if (isset($pl['opt']['bs']['s']AND in_array($pl['opt']['bs']['s']$bstyles)) {
  4864.                             $annots .= ' /S /'.$pl['opt']['bs']['s'];
  4865.                         }
  4866.                         if (isset($pl['opt']['bs']['d']AND (is_array($pl['opt']['bs']['d']))) {
  4867.                             $annots .= ' /D [';
  4868.                             foreach ($pl['opt']['bs']['d'as $cord{
  4869.                                 $cord floatval($cord);
  4870.                                 $annots .= sprintf(" %.4f"$cord);
  4871.                             }
  4872.                             $annots .= ']';
  4873.                         }
  4874.                         $annots .= '>> ';
  4875.                     }
  4876.                     if (isset($pl['opt']['be']AND (is_array($pl['opt']['be']))) {
  4877.                         $annots .= ' /BE <<';
  4878.                         $bstyles array('S''C');
  4879.                         if (isset($pl['opt']['be']['s']AND in_array($pl['opt']['be']['s']$markups)) {
  4880.                             $annots .= ' /S /'.$pl['opt']['bs']['s'];
  4881.                         else {
  4882.                             $annots .= ' /S /S';
  4883.                         }
  4884.                         if (isset($pl['opt']['be']['i']AND ($pl['opt']['be']['i'>= 0AND ($pl['opt']['be']['i'<= 2)) {
  4885.                             $annots .= ' /I '.sprintf(" %.4f"$pl['opt']['be']['i']);
  4886.                         }
  4887.                         $annots .= '>>';
  4888.                     }
  4889.                     $annots .= ' /C [';
  4890.                     if (isset($pl['opt']['c']AND (is_array($pl['opt']['c']))) {
  4891.                         foreach ($pl['opt']['c'as $col{
  4892.                             $col intval($col);
  4893.                             $color $col <= ($col >= 255 $col 255);
  4894.                             $annots .= sprintf(" %.4f"$color);
  4895.                         }
  4896.                     }
  4897.                     $annots .= ']';
  4898.                     //$annots .= ' /StructParent ';
  4899.                     //$annots .= ' /OC ';
  4900.                     $markups array('text''freetext''line''square''circle''polygon''polyline''highlight',  'underline''squiggly''strikeout''stamp''caret''ink''fileattachment''sound');
  4901.                     if (in_array(strtolower($pl['opt']['subtype'])$markups)) {
  4902.                         // this is a markup type
  4903.                         if (isset($pl['opt']['t']AND is_string($pl['opt']['t'])) {
  4904.                             $annots .= ' /T '.$this->_textstring($pl['opt']['t']);
  4905.                         }
  4906.                         //$annots .= ' /Popup ';
  4907.                         if (isset($pl['opt']['ca'])) {
  4908.                             $annots .= ' /CA '.sprintf("%.4f"floatval($pl['opt']['ca']));
  4909.                         }
  4910.                         if (isset($pl['opt']['rc'])) {
  4911.                             $annots .= ' /RC '.$this->_textstring($pl['opt']['rc']);
  4912.                         }
  4913.                         $annots .= ' /CreationDate '.$this->_datastring('D:'.date('YmdHis'));
  4914.                         //$annots .= ' /IRT ';
  4915.                         if (isset($pl['opt']['subj'])) {
  4916.                             $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj']);
  4917.                         }
  4918.                         //$annots .= ' /RT ';
  4919.                         //$annots .= ' /IT ';
  4920.                         //$annots .= ' /ExData ';
  4921.                     }
  4922.                     switch (strtolower($pl['opt']['subtype'])) {
  4923.                         case 'text'{
  4924.                             if (isset($pl['opt']['open'])) {
  4925.                                 $annots .= ' /Open '(strtolower($pl['opt']['open']== 'true' 'true' 'false');
  4926.                             }
  4927.                             $iconsapp array('Comment''Help''Insert''Key''NewParagraph''Note''Paragraph');
  4928.                             if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  4929.                                 $annots .= ' /Name /'.$pl['opt']['name'];
  4930.                             else {
  4931.                                 $annots .= ' /Name /Note';
  4932.                             }
  4933.                             $statemodels array('Marked''Review');
  4934.                             if (isset($pl['opt']['statemodel']AND in_array($pl['opt']['statemodel']$statemodels)) {
  4935.                                 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  4936.                             else {
  4937.                                 $pl['opt']['statemodel''Marked';
  4938.                                 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  4939.                             }
  4940.                             if ($pl['opt']['statemodel'== 'Marked'{
  4941.                                 $states array('Accepted''Unmarked');
  4942.                             else {
  4943.                                 $states array('Accepted''Rejected''Cancelled''Completed''None');
  4944.                             }
  4945.                             if (isset($pl['opt']['state']AND in_array($pl['opt']['state']$states)) {
  4946.                                 $annots .= ' /State /'.$pl['opt']['state'];
  4947.                             else {
  4948.                                 if ($pl['opt']['statemodel'== 'Marked'{
  4949.                                     $annots .= ' /State /Unmarked';
  4950.                                 else {
  4951.                                     $annots .= ' /State /None';
  4952.                                 }
  4953.                             }
  4954.                             break;
  4955.                         }
  4956.                         case 'link'{
  4957.                             if(is_string($pl['txt'])) {
  4958.                                 // external URI link
  4959.                                 $annots .= ' /A <</S /URI /URI '.$this->_datastring($pl['txt']).'>>';
  4960.                             else {
  4961.                                 // internal link
  4962.                                 $l $this->links[$pl['txt']];
  4963.                                 $annots .= sprintf(' /Dest [%d 0 R /XYZ 0 %.2f null]'(($l[0]))($this->pagedim[$l[0]]['h'($l[1$this->k)));
  4964.                             }
  4965.                             $hmodes array('N''I''O''P');
  4966.                             if (isset($pl['opt']['h']AND in_array($pl['opt']['h']$hmodes)) {
  4967.                                 $annots .= ' /H /'.$pl['opt']['h'];
  4968.                             else {
  4969.                                 $annots .= ' /H /I';
  4970.                             }
  4971.                             //$annots .= ' /PA ';
  4972.                             //$annots .= ' /Quadpoints ';
  4973.                             break;
  4974.                         }
  4975.                         case 'freetext'{
  4976.                             $annots .= ' /DA '.$this->_textstring($pl['txt']);
  4977.                             if (isset($pl['opt']['q']AND ($pl['opt']['q'>= 0AND ($pl['opt']['q'<= 2)) {
  4978.                                 $annots .= ' /Q '.intval($pl['opt']['q']);
  4979.                             }
  4980.                             if (isset($pl['opt']['rc'])) {
  4981.                                 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc']);
  4982.                             }
  4983.                             if (isset($pl['opt']['ds'])) {
  4984.                                 $annots .= ' /DS '.$this->_textstring($pl['opt']['ds']);
  4985.                             }
  4986.                             if (isset($pl['opt']['cl']AND is_array($pl['opt']['cl'])) {
  4987.                                 $annots .= ' /CL [';
  4988.                                 foreach ($pl['opt']['cl'as $cl{
  4989.                                     $annots .= sprintf("%.4f "$cl $this->k);
  4990.                                 }
  4991.                                 $annots .= ']';
  4992.                             }
  4993.                             $tfit array('FreeTextCallout''FreeTextTypeWriter');
  4994.                             if (isset($pl['opt']['it']AND in_array($pl['opt']['it']$tfit)) {
  4995.                                 $annots .= ' /IT '.$pl['opt']['it'];
  4996.                             }
  4997.                             if (isset($pl['opt']['rd']AND is_array($pl['opt']['rd'])) {
  4998.                                 $l $pl['opt']['rd'][0$this->k;
  4999.                                 $r $pl['opt']['rd'][1$this->k;
  5000.                                 $t $pl['opt']['rd'][2$this->k;
  5001.                                 $b $pl['opt']['rd'][3$this->k;
  5002.                                 $annots .= ' /RD ['.sprintf('%.2f %.2f %.2f %.2f'$l$r$t$b).']';
  5003.                             }
  5004.                             //$annots .= ' /LE ';
  5005.                             break;
  5006.                         }
  5007.                         // ... to be completed ...
  5008.                         case 'line'{
  5009.                             break;
  5010.                         }
  5011.                         case 'square'{
  5012.                             break;
  5013.                         }
  5014.                         case 'circle'{
  5015.                             break;
  5016.                         }
  5017.                         case 'polygon'{
  5018.                             break;
  5019.                         }
  5020.                         case 'polyline'{
  5021.                             break;
  5022.                         }
  5023.                         case 'highlight'{
  5024.                             break;
  5025.                         }
  5026.                         case 'underline'{
  5027.                             break;
  5028.                         }
  5029.                         case 'squiggly'{
  5030.                             break;
  5031.                         }
  5032.                         case 'strikeout'{
  5033.                             break;
  5034.                         }
  5035.                         case 'stamp'{
  5036.                             break;
  5037.                         }
  5038.                         case 'caret'{
  5039.                             break;
  5040.                         }
  5041.                         case 'ink'{
  5042.                             break;
  5043.                         }
  5044.                         case 'popup'{
  5045.                             break;
  5046.                         }
  5047.                         case 'fileattachment'{
  5048.                             if (!isset($pl['opt']['fs'])) {
  5049.                                 break;
  5050.                             }
  5051.                             $filename basename($pl['opt']['fs']);
  5052.                             if (isset($this->embeddedfiles[$filename]['n'])) {
  5053.                                 $annots .= ' /FS <</Type /Filespec /F '.$this->_datastring($filename).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  5054.                                 $iconsapp array('Graph''Paperclip''PushPin''Tag');
  5055.                                 if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  5056.                                     $annots .= ' /Name /'.$pl['opt']['name'];
  5057.                                 else {
  5058.                                     $annots .= ' /Name /PushPin';
  5059.                                 }
  5060.                             }
  5061.                             break;
  5062.                         }
  5063.                         case 'sound'{
  5064.                             if (!isset($pl['opt']['sound'])) {
  5065.                                 break;
  5066.                             }
  5067.                             $filename basename($pl['opt']['sound']);
  5068.                             if (isset($this->embeddedfiles[$filename]['n'])) {
  5069.                                 // to be completed...
  5070.                                 $iconsapp array('Speaker''Mic');
  5071.                                 if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  5072.                                     $annots .= ' /Name /'.$pl['opt']['name'];
  5073.                                 else {
  5074.                                     $annots .= ' /Name /Speaker';
  5075.                                 }
  5076.                             }
  5077.                             break;
  5078.                         }
  5079.                         case 'movie'{
  5080.                             break;
  5081.                         }
  5082.                         case 'widget'{
  5083.                             break;
  5084.                         }
  5085.                         case 'screen'{
  5086.                             break;
  5087.                         }
  5088.                         case 'printermark'{
  5089.                             break;
  5090.                         }
  5091.                         case 'trapnet'{
  5092.                             break;
  5093.                         }
  5094.                         case 'watermark'{
  5095.                             break;
  5096.                         }
  5097.                         case '3d'{
  5098.                             break;
  5099.                         }
  5100.                         default{
  5101.                             break;
  5102.                         }
  5103.                     }
  5104.                     
  5105.                 $annots .= '>>';
  5106.                 }
  5107.                 $annots .= "\n]";
  5108.                 $this->_out($annots);
  5109.             }
  5110.         }
  5111.  
  5112.         /**
  5113.         * Output fonts.
  5114.         * @access protected
  5115.         */
  5116.         protected function _putfonts({
  5117.             $nf $this->n;
  5118.             foreach ($this->diffs as $diff{
  5119.                 //Encodings
  5120.                 $this->_newobj();
  5121.                 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  5122.                 $this->_out('endobj');
  5123.             }
  5124.             $mqr get_magic_quotes_runtime();
  5125.             set_magic_quotes_runtime(0);
  5126.             foreach ($this->FontFiles as $file => $info{
  5127.                 // search and get font file to embedd
  5128.                 $fontdir $info['fontdir'];
  5129.                 $file strtolower($file);
  5130.                 $fontfile '';
  5131.                 // search files on various directories
  5132.                 if (file_exists($fontdir.$file)) {
  5133.                     $fontfile $fontdir.$file;
  5134.                 elseif (file_exists($this->_getfontpath().$file)) {
  5135.                     $fontfile $this->_getfontpath().$file;
  5136.                 elseif (file_exists($file)) {
  5137.                     $fontfile $file;
  5138.                 }
  5139.                 if (!empty($fontfile)) {
  5140.                     $font file_get_contents($fontfile);
  5141.                     $compressed (substr($file-2== '.z');
  5142.                     if ((!$compressedAND (isset($info['length2']))) {
  5143.                         $header (ord($font{0}== 128);
  5144.                         if ($header{
  5145.                             //Strip first binary header
  5146.                             $font substr($font6);
  5147.                         }
  5148.                         if ($header AND (ord($font{$info['length1']}== 128)) {
  5149.                             //Strip second binary header
  5150.                             $font substr($font0$info['length1']).substr($font($info['length1'6));
  5151.                         }
  5152.                     }
  5153.                     $this->_newobj();
  5154.                     $this->FontFiles[$file]['n'$this->n;
  5155.                     $this->_out('<</Length '.strlen($font));
  5156.                     if ($compressed{
  5157.                         $this->_out('/Filter /FlateDecode');
  5158.                     }
  5159.                     $this->_out('/Length1 '.$info['length1']);
  5160.                     if (isset($info['length2'])) {
  5161.                         $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  5162.                     }
  5163.                     $this->_out('>>');
  5164.                     $this->_putstream($font);
  5165.                     $this->_out('endobj');
  5166.                 }
  5167.             }
  5168.             set_magic_quotes_runtime($mqr);
  5169.             foreach ($this->fontkeys as $k{
  5170.                 //Font objects
  5171.                 $this->setFontSubBuffer($k'n'$this->n + 1);
  5172.                 $font $this->getFontBuffer($k);
  5173.                 $type $font['type'];
  5174.                 $name $font['name'];
  5175.                 if ($type == 'core'{
  5176.                     //Standard font
  5177.                     $this->_newobj();
  5178.                     $this->_out('<</Type /Font');
  5179.                     $this->_out('/BaseFont /'.$name);
  5180.                     $this->_out('/Subtype /Type1');
  5181.                     if (($name != 'symbol'AND ($name != 'zapfdingbats')) {
  5182.                         $this->_out('/Encoding /WinAnsiEncoding');
  5183.                     }
  5184.                     $this->_out('>>');
  5185.                     $this->_out('endobj');
  5186.                 elseif (($type == 'Type1'OR ($type == 'TrueType')) {
  5187.                     //Additional Type1 or TrueType font
  5188.                     $this->_newobj();
  5189.                     $this->_out('<</Type /Font');
  5190.                     $this->_out('/BaseFont /'.$name);
  5191.                     $this->_out('/Subtype /'.$type);
  5192.                     $this->_out('/FirstChar 32 /LastChar 255');
  5193.                     $this->_out('/Widths '.($this->n + 1).' 0 R');
  5194.                     $this->_out('/FontDescriptor '.($this->n + 2).' 0 R');
  5195.                     if ($font['enc']{
  5196.                         if (isset($font['diff'])) {
  5197.                             $this->_out('/Encoding '.($nf $font['diff']).' 0 R');
  5198.                         else {
  5199.                             $this->_out('/Encoding /WinAnsiEncoding');
  5200.                         }
  5201.                     }
  5202.                     $this->_out('>>');
  5203.                     $this->_out('endobj');
  5204.                     // Widths
  5205.                     $this->_newobj();
  5206.                     $cw &$font['cw'];
  5207.                     $s '[';
  5208.                     for($i 32$i 256++$i{
  5209.                         $s .= $cw[$i].' ';
  5210.                     }
  5211.                     $this->_out($s.']');
  5212.                     $this->_out('endobj');
  5213.                     //Descriptor
  5214.                     $this->_newobj();
  5215.                     $s '<</Type /FontDescriptor /FontName /'.$name;
  5216.                     foreach ($font['desc'as $k => $v{
  5217.                         $s .= ' /'.$k.' '.$v.'';
  5218.                     }
  5219.                     if (!empty($font['file'])) {
  5220.                         $s .= ' /FontFile'.($type == 'Type1' '' '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  5221.                     }
  5222.                     $this->_out($s.'>>');
  5223.                     $this->_out('endobj');
  5224.                 else {
  5225.                     //Allow for additional types
  5226.                     $mtd '_put'.strtolower($type);
  5227.                     if (!method_exists($this$mtd)) {
  5228.                         $this->Error('Unsupported font type: '.$type);
  5229.                     }
  5230.                     $this->$mtd($font);
  5231.                 }
  5232.             }
  5233.         }
  5234.         
  5235.         /**
  5236.         * Outputs font widths
  5237.         * @parameter array $font font data
  5238.         * @parameter int $cidoffset offset for CID values
  5239.         * @author Nicola Asuni
  5240.         * @access protected
  5241.         * @since 4.4.000 (2008-12-07)
  5242.         */
  5243.         protected function _putfontwidths($font$cidoffset=0{
  5244.             ksort($font['cw']);
  5245.             $rangeid 0;
  5246.             $range array();
  5247.             $prevcid = -2;
  5248.             $prevwidth = -1;
  5249.             $interval false;
  5250.             // for each character
  5251.             foreach ($font['cw'as $cid => $width{
  5252.                 $cid -= $cidoffset;
  5253.                 if ($width != $font['dw']{    
  5254.                     if ($cid == ($prevcid 1)) {
  5255.                         // consecutive CID
  5256.                         if ($width == $prevwidth{
  5257.                             if ($width == $range[$rangeid][0]{
  5258.                                 $range[$rangeid][$width;
  5259.                             else {
  5260.                                 array_pop($range[$rangeid]);
  5261.                                 // new range
  5262.                                 $rangeid $prevcid;
  5263.                                 $range[$rangeidarray();
  5264.                                 $range[$rangeid][$prevwidth;
  5265.                                 $range[$rangeid][$width;
  5266.                             }
  5267.                             $interval true;
  5268.                             $range[$rangeid]['interval'true;
  5269.                         else {
  5270.                             if ($interval{
  5271.                                 // new range
  5272.                                 $rangeid $cid;
  5273.                                 $range[$rangeidarray();
  5274.                                 $range[$rangeid][$width;
  5275.                             else {
  5276.                                 $range[$rangeid][$width;
  5277.                             }
  5278.                             $interval false;
  5279.                         }
  5280.                     else {
  5281.                         // new range
  5282.                         $rangeid $cid;
  5283.                         $range[$rangeidarray();
  5284.                         $range[$rangeid][$width;
  5285.                         $interval false;
  5286.                     }
  5287.                     $prevcid $cid;
  5288.                     $prevwidth $width;
  5289.                 }
  5290.             }
  5291.             // optimize ranges
  5292.             $prevk = -1;
  5293.             $nextk = -1;
  5294.             $prevint false;
  5295.             foreach ($range as $k => $ws{
  5296.                 $cws count($ws);
  5297.                 if (($k == $nextkAND (!$previntAND ((!isset($ws['interval'])) OR ($cws 4))) {
  5298.                     if (isset($range[$k]['interval'])) {
  5299.                         unset($range[$k]['interval']);
  5300.                     }
  5301.                     $range[$prevkarray_merge($range[$prevk]$range[$k]);
  5302.                     unset($range[$k]);
  5303.                 else {
  5304.                     $prevk $k;
  5305.                 }
  5306.                 $nextk $k $cws;
  5307.                 if (isset($ws['interval'])) {
  5308.                     if ($cws 3{
  5309.                         $prevint true;
  5310.                     else {
  5311.                         $prevint false;
  5312.                     }
  5313.                     unset($range[$k]['interval']);
  5314.                     --$nextk;
  5315.                 else {
  5316.                     $prevint false;
  5317.                 }
  5318.             }
  5319.             // output data
  5320.             $w '';
  5321.             foreach ($range as $k => $ws{
  5322.                 if (count(array_count_values($ws)) == 1{
  5323.                     // interval mode is more compact
  5324.                     $w .= ' '.$k.' '.($k count($ws1).' '.$ws[0];
  5325.                 else {
  5326.                     // range mode
  5327.                     $w .= ' '.$k.' [ '.implode(' '$ws).' ]';
  5328.                 }
  5329.             }
  5330.             $this->_out('/W ['.$w.' ]');
  5331.         }
  5332.         
  5333.         /**
  5334.         * Adds unicode fonts.<br>
  5335.         * Based on PDF Reference 1.3 (section 5)
  5336.         * @parameter array $font font data
  5337.         * @access protected
  5338.         * @author Nicola Asuni
  5339.         * @since 1.52.0.TC005 (2005-01-05)
  5340.         */
  5341.         protected function _puttruetypeunicode($font{
  5342.             // Type0 Font
  5343.             // A composite font composed of other fonts, organized hierarchically
  5344.             $this->_newobj();
  5345.             $this->_out('<</Type /Font');
  5346.             $this->_out('/Subtype /Type0');
  5347.             $this->_out('/BaseFont /'.$font['name'].'');
  5348.             $this->_out('/Encoding /Identity-H')//The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values.
  5349.             $this->_out('/ToUnicode /Identity-H');
  5350.             $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  5351.             $this->_out('>>');
  5352.             $this->_out('endobj');
  5353.             // CIDFontType2
  5354.             // A CIDFont whose glyph descriptions are based on TrueType font technology
  5355.             $this->_newobj();
  5356.             $this->_out('<</Type /Font');
  5357.             $this->_out('/Subtype /CIDFontType2');
  5358.             $this->_out('/BaseFont /'.$font['name'].'');
  5359.             // A dictionary containing entries that define the character collection of the CIDFont.
  5360.             $cidinfo '/Registry '.$this->_datastring('Adobe');
  5361.             $cidinfo .= ' /Ordering '.$this->_datastring('Identity');
  5362.             $cidinfo .= ' /Supplement 0';
  5363.             $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  5364.             $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  5365.             $this->_out('/DW '.$font['dw'].'')// default width
  5366.             $this->_putfontwidths($font0);
  5367.             $this->_out('/CIDToGIDMap '.($this->n + 2).' 0 R');
  5368.             $this->_out('>>');
  5369.             $this->_out('endobj');            
  5370.             // Font descriptor
  5371.             // A font descriptor describing the CIDFont default metrics other than its glyph widths
  5372.             $this->_newobj();
  5373.             $this->_out('<</Type /FontDescriptor');
  5374.             $this->_out('/FontName /'.$font['name']);
  5375.             foreach ($font['desc'as $key => $value{
  5376.                 $this->_out('/'.$key.' '.$value);
  5377.             }
  5378.             $fontdir '';
  5379.             if (!empty($font['file'])) {
  5380.                 // A stream containing a TrueType font
  5381.                 $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
  5382.                 $fontdir $this->FontFiles[$font['file']]['fontdir'];
  5383.             }
  5384.             $this->_out('>>');
  5385.             $this->_out('endobj');
  5386.             $this->_newobj();
  5387.             if (isset($font['ctg']AND (!empty($font['ctg']))) {
  5388.                 // Embed CIDToGIDMap
  5389.                 // A specification of the mapping from CIDs to glyph indices
  5390.                 // search and get CTG font file to embedd
  5391.                 $ctgfile strtolower($font['ctg']);
  5392.                 // search and get ctg font file to embedd
  5393.                 $fontfile '';
  5394.                 // search files on various directories
  5395.                 if (file_exists($fontdir.$ctgfile)) {
  5396.                     $fontfile $fontdir.$ctgfile;
  5397.                 elseif (file_exists($this->_getfontpath().$ctgfile)) {
  5398.                     $fontfile $this->_getfontpath().$ctgfile;
  5399.                 elseif (file_exists($ctgfile)) {
  5400.                     $fontfile $ctgfile;
  5401.                 }
  5402.                 if (empty($fontfile)) {
  5403.                     $this->Error('Font file not found: '.$ctgfile);
  5404.                 }
  5405.                 $size filesize($fontfile);
  5406.                 $this->_out('<</Length '.$size.'');
  5407.                 if (substr($fontfile-2== '.z'// check file extension
  5408.                     // Decompresses data encoded using the public-domain 
  5409.                     // zlib/deflate compression method, reproducing the 
  5410.                     // original text or binary data
  5411.                     $this->_out('/Filter /FlateDecode');
  5412.                 }
  5413.                 $this->_out('>>');
  5414.                 $this->_putstream(file_get_contents($fontfile));
  5415.             }
  5416.             $this->_out('endobj');
  5417.         }
  5418.         
  5419.         /**
  5420.          * Output CID-0 fonts.
  5421.          * @param array $font font data
  5422.          * @access protected
  5423.          * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  5424.          * @since 3.2.000 (2008-06-23)
  5425.          */
  5426.         protected function _putcidfont0($font{
  5427.             $cidoffset 31;
  5428.             if (isset($font['cidinfo']['uni2cid'])) {
  5429.                 // convert unicode to cid.
  5430.                 $uni2cid $font['cidinfo']['uni2cid'];
  5431.                 $cw array();
  5432.                 foreach ($font['cw'as $uni => $width{
  5433.                     if (isset($uni2cid[$uni])) {
  5434.                         $cw[($uni2cid[$uni$cidoffset)$width;
  5435.                     elseif ($uni 256{
  5436.                         $cw[$uni$width;
  5437.                     // else unknown character
  5438.                 }
  5439.                 $font array_merge($fontarray('cw' => $cw));
  5440.             }
  5441.             $name $font['name'];
  5442.             $enc $font['enc'];
  5443.             if ($enc{
  5444.                 $longname $name.'-'.$enc;
  5445.             else {
  5446.                 $longname $name;
  5447.             }
  5448.             $this->_newobj();
  5449.             $this->_out('<</Type /Font');
  5450.             $this->_out('/BaseFont /'.$longname);
  5451.             $this->_out('/Subtype /Type0');
  5452.             if ($enc{
  5453.                 $this->_out('/Encoding /'.$enc);
  5454.             }
  5455.             $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  5456.             $this->_out('>>');
  5457.             $this->_out('endobj');
  5458.             $this->_newobj();
  5459.             $this->_out('<</Type /Font');
  5460.             $this->_out('/BaseFont /'.$name);
  5461.             $this->_out('/Subtype /CIDFontType0');
  5462.             $cidinfo '/Registry '.$this->_datastring($font['cidinfo']['Registry']);
  5463.             $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']);
  5464.             $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  5465.             $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  5466.             $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  5467.             $this->_out('/DW '.$font['dw']);
  5468.             $this->_putfontwidths($font$cidoffset);
  5469.             $this->_out('>>');
  5470.             $this->_out('endobj');
  5471.             $this->_newobj();
  5472.             $s '<</Type /FontDescriptor /FontName /'.$name;
  5473.             foreach ($font['desc'as $k => $v{
  5474.                 if ($k != 'Style'{
  5475.                     $s .= ' /'.$k.' '.$v.'';
  5476.                 }
  5477.             }
  5478.             $this->_out($s.'>>');
  5479.             $this->_out('endobj');
  5480.         }
  5481.  
  5482.         /**
  5483.          * Output images.
  5484.          * @access protected
  5485.          */
  5486.         protected function _putimages({
  5487.             $filter ($this->compress'/Filter /FlateDecode ' '';
  5488.             foreach ($this->imagekeys as $file{
  5489.                 $info $this->getImageBuffer($file);
  5490.                 $this->_newobj();
  5491.                 $this->setImageSubBuffer($file'n'$this->n);
  5492.                 $this->_out('<</Type /XObject');
  5493.                 $this->_out('/Subtype /Image');
  5494.                 $this->_out('/Width '.$info['w']);
  5495.                 $this->_out('/Height '.$info['h']);
  5496.                 if (isset($info['masked'])) {
  5497.                     $this->_out('/SMask '.($this->n - 1).' 0 R');
  5498.                 }
  5499.                 if ($info['cs'== 'Indexed'{
  5500.                     $this->_out('/ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']31).' '.($this->n + 1).' 0 R]');
  5501.                 else {
  5502.                     $this->_out('/ColorSpace /'.$info['cs']);
  5503.                     if ($info['cs'== 'DeviceCMYK'{
  5504.                         $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  5505.                     }
  5506.                 }
  5507.                 $this->_out('/BitsPerComponent '.$info['bpc']);
  5508.                 if (isset($info['f'])) {
  5509.                     $this->_out('/Filter /'.$info['f']);
  5510.                 }
  5511.                 if (isset($info['parms'])) {
  5512.                     $this->_out($info['parms']);
  5513.                 }
  5514.                 if (isset($info['trns']AND is_array($info['trns'])) {
  5515.                     $trns='';
  5516.                     $count_info count($info['trns']);
  5517.                     for($i=0$i $count_info++$i{
  5518.                         $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  5519.                     }
  5520.                     $this->_out('/Mask ['.$trns.']');
  5521.                 }
  5522.                 $this->_out('/Length '.strlen($info['data']).'>>');
  5523.                 $this->_putstream($info['data']);
  5524.                 $this->_out('endobj');
  5525.                 //Palette
  5526.                 if ($info['cs'== 'Indexed'{
  5527.                     $this->_newobj();
  5528.                     $pal ($this->compressgzcompress($info['pal']$info['pal'];
  5529.                     $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  5530.                     $this->_putstream($pal);
  5531.                     $this->_out('endobj');
  5532.                 }
  5533.             }
  5534.         }
  5535.  
  5536.         /**
  5537.         * Output Spot Colors Resources.
  5538.         * @access protected
  5539.         * @since 4.0.024 (2008-09-12)
  5540.         */
  5541.         protected function _putspotcolors({
  5542.             foreach ($this->spot_colors as $name => $color{
  5543.                 $this->_newobj();
  5544.                 $this->spot_colors[$name]['n'$this->n;
  5545.                 $this->_out('[/Separation /'.str_replace(' ''#20'$name));
  5546.                 $this->_out('/DeviceCMYK <<');
  5547.                 $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  5548.                 $this->_out(sprintf('/C1 [%.4f %.4f %.4f %.4f] '$color['c']/100$color['m']/100$color['y']/100$color['k']/100));
  5549.                 $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  5550.                 $this->_out('endobj');
  5551.             }
  5552.         }
  5553.  
  5554.         /**
  5555.         * Output object dictionary for images.
  5556.         * @access protected
  5557.         */
  5558.         protected function _putxobjectdict({
  5559.             foreach ($this->imagekeys as $file{
  5560.                 $info $this->getImageBuffer($file);
  5561.                 $this->_out('/I'.$info['i'].' '.$info['n'].' 0 R');
  5562.             }
  5563.         }
  5564.  
  5565.         /**
  5566.         * Output Resources Dictionary.
  5567.         * @access protected
  5568.         */
  5569.         protected function _putresourcedict({
  5570.             $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  5571.             $this->_out('/Font <<');
  5572.             foreach ($this->fontkeys as $fontkey{
  5573.                 $font $this->getFontBuffer($fontkey);
  5574.                 $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  5575.             }
  5576.             $this->_out('>>');
  5577.             $this->_out('/XObject <<');
  5578.             $this->_putxobjectdict();
  5579.             $this->_out('>>');
  5580.             // visibility
  5581.             $this->_out('/Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R>>');
  5582.             // transparency
  5583.             $this->_out('/ExtGState <<');
  5584.             foreach ($this->extgstates as $k => $extgstate{
  5585.                 $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  5586.             }
  5587.             $this->_out('>>');
  5588.             // gradients
  5589.             if (isset($this->gradientsAND (count($this->gradients0)) {
  5590.                 $this->_out('/Shading <<');
  5591.                 foreach ($this->gradients as $id => $grad{
  5592.                     $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  5593.                 }
  5594.                 $this->_out('>>');
  5595.             }
  5596.             // spot colors
  5597.             if (isset($this->spot_colorsAND (count($this->spot_colors0)) {
  5598.                 $this->_out('/ColorSpace <<');
  5599.                 foreach ($this->spot_colors as $color{
  5600.                     $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  5601.                 }
  5602.                 $this->_out('>>');
  5603.             }
  5604.         }
  5605.         
  5606.         /**
  5607.         * Output Resources.
  5608.         * @access protected
  5609.         */
  5610.         protected function _putresources({
  5611.             $this->_putextgstates();
  5612.             $this->_putocg();
  5613.             $this->_putfonts();
  5614.             $this->_putimages();
  5615.             $this->_putspotcolors();
  5616.             $this->_putshaders();
  5617.             //Resource dictionary
  5618.             $this->offsets[2$this->bufferlen;
  5619.             $this->_out('2 0 obj');
  5620.             $this->_out('<<');
  5621.             $this->_putresourcedict();
  5622.             $this->_out('>>');
  5623.             $this->_out('endobj');
  5624.             $this->_putjavascript();
  5625.             $this->_putbookmarks();
  5626.             $this->_putEmbeddedFiles();
  5627.             // encryption
  5628.             if ($this->encrypted{
  5629.                 $this->_newobj();
  5630.                 $this->enc_obj_id = $this->n;
  5631.                 $this->_out('<<');
  5632.                 $this->_putencryption();
  5633.                 $this->_out('>>');
  5634.                 $this->_out('endobj');
  5635.             }
  5636.         }
  5637.         
  5638.         /**
  5639.         * Adds some Metadata information
  5640.         * (see Chapter 10.2 of PDF Reference)
  5641.         * @access protected
  5642.         */
  5643.         protected function _putinfo({
  5644.             if (!empty($this->title)) {
  5645.                 $this->_out('/Title '.$this->_textstring($this->title));
  5646.             }
  5647.             if (!empty($this->author)) {
  5648.                 $this->_out('/Author '.$this->_textstring($this->author));
  5649.             }
  5650.             if (!empty($this->subject)) {
  5651.                 $this->_out('/Subject '.$this->_textstring($this->subject));
  5652.             }
  5653.             if (!empty($this->keywords)) {
  5654.                 $this->_out('/Keywords '.$this->_textstring($this->keywords));
  5655.             }
  5656.             if (!empty($this->creator)) {
  5657.                 $this->_out('/Creator '.$this->_textstring($this->creator));
  5658.             }
  5659.             if (defined('PDF_PRODUCER')) {
  5660.                 $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER));
  5661.             }
  5662.             $this->_out('/CreationDate '.$this->_datastring('D:'.date('YmdHis')));
  5663.             $this->_out('/ModDate '.$this->_datastring('D:'.date('YmdHis')));    
  5664.         }
  5665.         
  5666.         /**
  5667.         * Output Catalog.
  5668.         * @access protected
  5669.         */
  5670.         protected function _putcatalog({
  5671.             $this->_out('/Type /Catalog');
  5672.             $this->_out('/Pages 1 0 R');
  5673.             if ($this->ZoomMode == 'fullpage'{
  5674.                 $this->_out('/OpenAction [3 0 R /Fit]');
  5675.             elseif ($this->ZoomMode == 'fullwidth'{
  5676.                 $this->_out('/OpenAction [3 0 R /FitH null]');
  5677.             elseif ($this->ZoomMode == 'real'{
  5678.                 $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  5679.             elseif (!is_string($this->ZoomMode)) {
  5680.                 $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode / 100).']');
  5681.             }
  5682.             if (isset($this->LayoutModeAND (!empty($this->LayoutMode))) {
  5683.                 $this->_out('/PageLayout /'.$this->LayoutMode.'');
  5684.             }
  5685.             if (isset($this->PageModeAND (!empty($this->PageMode))) {
  5686.                 $this->_out('/PageMode /'.$this->PageMode);
  5687.             }
  5688.             if (isset($this->l['a_meta_language'])) {
  5689.                 $this->_out('/Lang /'.$this->l['a_meta_language']);
  5690.             }
  5691.             $this->_out('/Names <<');
  5692.             if (!empty($this->javascript)) {
  5693.                 $this->_out('/JavaScript '.($this->n_js).' 0 R');
  5694.             }
  5695.             $this->_out('>>');
  5696.             if (count($this->outlines0{
  5697.                 $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  5698.                 $this->_out('/PageMode /UseOutlines');
  5699.             }
  5700.             $this->_putviewerpreferences();
  5701.             $p $this->n_ocg_print.' 0 R';
  5702.             $v $this->n_ocg_view.' 0 R';
  5703.             $as '<</Event /Print /OCGs ['.$p.' '.$v.'] /Category [/Print]>> <</Event /View /OCGs ['.$p.' '.$v.'] /Category [/View]>>';
  5704.             $this->_out('/OCProperties <</OCGs ['.$p.' '.$v.'] /D <</ON ['.$p.'] /OFF ['.$v.'] /AS ['.$as.']>>>>');
  5705.             $this->_putuserrights();
  5706.         }
  5707.         
  5708.         /**
  5709.         * Output viewer preferences.
  5710.         * @author Nicola asuni
  5711.         * @since 3.1.000 (2008-06-09)
  5712.         * @access protected
  5713.         */
  5714.         protected function _putviewerpreferences({
  5715.             $this->_out('/ViewerPreferences<<');
  5716.             if ($this->rtl{
  5717.                 $this->_out('/Direction /R2L');
  5718.             else {
  5719.                 $this->_out('/Direction /L2R');
  5720.             }
  5721.             if (isset($this->viewer_preferences['HideToolbar']AND ($this->viewer_preferences['HideToolbar'])) {
  5722.                 $this->_out('/HideToolbar true');
  5723.             }
  5724.             if (isset($this->viewer_preferences['HideMenubar']AND ($this->viewer_preferences['HideMenubar'])) {
  5725.                 $this->_out('/HideMenubar true');
  5726.             }
  5727.             if (isset($this->viewer_preferences['HideWindowUI']AND ($this->viewer_preferences['HideWindowUI'])) {
  5728.                 $this->_out('/HideWindowUI true');
  5729.             }
  5730.             if (isset($this->viewer_preferences['FitWindow']AND ($this->viewer_preferences['FitWindow'])) {
  5731.                 $this->_out('/FitWindow true');
  5732.             }
  5733.             if (isset($this->viewer_preferences['CenterWindow']AND ($this->viewer_preferences['CenterWindow'])) {
  5734.                 $this->_out('/CenterWindow true');
  5735.             }
  5736.             if (isset($this->viewer_preferences['DisplayDocTitle']AND ($this->viewer_preferences['DisplayDocTitle'])) {
  5737.                 $this->_out('/DisplayDocTitle true');
  5738.             }
  5739.             if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
  5740.                 $this->_out('/NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'].'');
  5741.             }
  5742.             if (isset($this->viewer_preferences['ViewArea'])) {
  5743.                 $this->_out('/ViewArea /'.$this->viewer_preferences['ViewArea']);
  5744.             }
  5745.             if (isset($this->viewer_preferences['ViewClip'])) {
  5746.                 $this->_out('/ViewClip /'.$this->viewer_preferences['ViewClip']);
  5747.             }
  5748.             if (isset($this->viewer_preferences['PrintArea'])) {
  5749.                 $this->_out('/PrintArea /'.$this->viewer_preferences['PrintArea']);
  5750.             }
  5751.             if (isset($this->viewer_preferences['PrintClip'])) {
  5752.                 $this->_out('/PrintClip /'.$this->viewer_preferences['PrintClip']);
  5753.             }
  5754.             if (isset($this->viewer_preferences['PrintScaling'])) {
  5755.                 $this->_out('/PrintScaling /'.$this->viewer_preferences['PrintScaling']);
  5756.             }
  5757.             if (isset($this->viewer_preferences['Duplex']AND (!empty($this->viewer_preferences['Duplex']))) {
  5758.                 $this->_out('/Duplex /'.$this->viewer_preferences['Duplex']);
  5759.             }
  5760.             if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
  5761.                 if ($this->viewer_preferences['PickTrayByPDFSize']{
  5762.                     $this->_out('/PickTrayByPDFSize true');
  5763.                 else {
  5764.                     $this->_out('/PickTrayByPDFSize false');
  5765.                 }
  5766.             }
  5767.             if (isset($this->viewer_preferences['PrintPageRange'])) {
  5768.                 $PrintPageRangeNum '';
  5769.                 foreach ($this->viewer_preferences['PrintPageRange'as $k => $v{
  5770.                     $PrintPageRangeNum .= ' '.($v 1).'';
  5771.                 }
  5772.                 $this->_out('/PrintPageRange ['.substr($PrintPageRangeNum,1).']');
  5773.             }
  5774.             if (isset($this->viewer_preferences['NumCopies'])) {
  5775.                 $this->_out('/NumCopies '.intval($this->viewer_preferences['NumCopies']));
  5776.             }
  5777.             $this->_out('>>');
  5778.         }
  5779.  
  5780.         /**
  5781.         * Output trailer.
  5782.         * @access protected
  5783.         */
  5784.         protected function _puttrailer({
  5785.             $this->_out('/Size '.($this->n + 1));
  5786.             $this->_out('/Root '.$this->n.' 0 R');
  5787.             $this->_out('/Info '.($this->n - 1).' 0 R');
  5788.             if ($this->encrypted{
  5789.                 $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  5790.                 $this->_out('/ID [()()]');
  5791.             }
  5792.         }
  5793.  
  5794.         /**
  5795.         * Output PDF header.
  5796.         * @access protected
  5797.         */
  5798.         protected function _putheader({
  5799.             $this->_out('%PDF-'.$this->PDFVersion);
  5800.         }
  5801.  
  5802.         /**
  5803.         * Output end of document (EOF).
  5804.         * @access protected
  5805.         */
  5806.         protected function _enddoc({
  5807.             $this->state = 1;
  5808.             $this->_putheader();
  5809.             $this->_putpages();
  5810.             $this->_putresources();
  5811.             //Info
  5812.             $this->_newobj();
  5813.             $this->_out('<<');
  5814.             $this->_putinfo();
  5815.             $this->_out('>>');
  5816.             $this->_out('endobj');
  5817.             //Catalog
  5818.             $this->_newobj();
  5819.             $this->_out('<<');
  5820.             $this->_putcatalog();
  5821.             $this->_out('>>');
  5822.             $this->_out('endobj');
  5823.             //Cross-ref
  5824.             $o $this->bufferlen;
  5825.             $this->_out('xref');
  5826.             $this->_out('0 '.($this->n + 1));
  5827.             $this->_out('0000000000 65535 f ');
  5828.             for($i=1$i <= $this->n++$i{
  5829.                 $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  5830.             }
  5831.             foreach ($this->embeddedfiles as $filename => $filedata{
  5832.                 $this->_out(sprintf('%010d 00000 n ',$this->offsets[$filedata['n']]));
  5833.             }
  5834.             //Trailer
  5835.             $this->_out('trailer');
  5836.             $this->_out('<<');
  5837.             $this->_puttrailer();
  5838.             $this->_out('>>');
  5839.             $this->_out('startxref');
  5840.             $this->_out($o);
  5841.             $this->_out('%%EOF');
  5842.             $this->state = 3// end-of-doc
  5843.             if ($this->diskcache{
  5844.                 // remove temporary files used for images
  5845.                 foreach ($this->imagekeys as $key{
  5846.                     // remove temporary files
  5847.                     unlink($this->images[$key]);
  5848.                 }
  5849.                 foreach ($this->fontkeys as $key{
  5850.                     // remove temporary files
  5851.                     unlink($this->fonts[$key]);
  5852.                 }
  5853.             }
  5854.         }
  5855.  
  5856.         /**
  5857.         * Initialize a new page.
  5858.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  5859.         * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  5860.         * @access protected
  5861.         */
  5862.         protected function _beginpage($orientation=''$format=''{
  5863.             ++$this->page;
  5864.             $this->setPageBuffer($this->page'');
  5865.             // initialize array for graphics tranformation positions inside a page buffer
  5866.             $this->transfmrk[$this->pagearray();
  5867.             $this->state = 2;
  5868.             if (empty($orientation)) {
  5869.                 if (isset($this->CurOrientation)) {
  5870.                     $orientation $this->CurOrientation;
  5871.                 else {
  5872.                     $orientation 'P';
  5873.                 }
  5874.             }
  5875.             if (!empty($format)) {
  5876.                 $this->setPageFormat($format$orientation);
  5877.             else {
  5878.                 $this->setPageOrientation($orientation);
  5879.             }
  5880.             if ($this->rtl{
  5881.                 $this->x = $this->w - $this->rMargin;
  5882.             else {
  5883.                 $this->x = $this->lMargin;
  5884.             }
  5885.             $this->y = $this->tMargin;
  5886.             if (isset($this->newpagegroup[$this->page])) {
  5887.                 // start a new group
  5888.                 $n sizeof($this->pagegroups1;
  5889.                 $alias '{nb'.$n.'}';
  5890.                 $this->pagegroups[$alias1;
  5891.                 $this->currpagegroup = $alias;
  5892.             elseif ($this->currpagegroup{
  5893.                 ++$this->pagegroups[$this->currpagegroup];
  5894.             }
  5895.         }
  5896.  
  5897.         /**
  5898.         * Mark end of page.
  5899.         * @access protected
  5900.         */
  5901.         protected function _endpage({
  5902.             $this->setVisibility('all');
  5903.             $this->state = 1;
  5904.         }
  5905.  
  5906.         /**
  5907.         * Begin a new object.
  5908.         * @access protected
  5909.         */
  5910.         protected function _newobj({
  5911.             ++$this->n;
  5912.             $this->offsets[$this->n$this->bufferlen;
  5913.             $this->_out($this->n.' 0 obj');
  5914.         }
  5915.  
  5916.         /**
  5917.         * Underline text.
  5918.         * @param int $x X coordinate
  5919.         * @param int $y Y coordinate
  5920.         * @param string $txt text to underline
  5921.         * @access protected
  5922.         */
  5923.         protected function _dounderline($x$y$txt{
  5924.             $up $this->CurrentFont['up'];
  5925.             $ut $this->CurrentFont['ut'];
  5926.             $w $this->GetStringWidth($txt);
  5927.             return sprintf('%.2f %.2f %.2f %.2f re f'$x $this->k($this->h - ($y $up 1000 $this->FontSize)) $this->k$w $this->k-$ut 1000 $this->FontSizePt);
  5928.         }
  5929.         
  5930.         /**
  5931.         * Line through text.
  5932.         * @param int $x X coordinate
  5933.         * @param int $y Y coordinate
  5934.         * @param string $txt text to linethrough
  5935.         * @access protected
  5936.         */
  5937.         protected function _dolinethrough($x$y$txt{
  5938.             $up $this->CurrentFont['up'];
  5939.             $ut $this->CurrentFont['ut'];
  5940.             $w $this->GetStringWidth($txt);
  5941.             return sprintf('%.2f %.2f %.2f %.2f re f'$x $this->k($this->h - ($y ($this->FontSize/2$up 1000 $this->FontSize)) $this->k$w $this->k-$ut 1000 $this->FontSizePt);
  5942.         }
  5943.         
  5944.         /**
  5945.         * Read a 4-byte integer from file.
  5946.         * @param string $f file name.
  5947.         * @return 4-byte integer
  5948.         * @access protected
  5949.         */
  5950.         protected function _freadint($f{
  5951.             $a unpack('Ni'fread($f,4));
  5952.             return $a['i'];
  5953.         }
  5954.         
  5955.         /**
  5956.         * Add "\" before "\", "(" and ")"
  5957.         * @param string $s string to escape.
  5958.         * @return string escaped string.
  5959.         * @access protected
  5960.         */
  5961.         protected function _escape($s{
  5962.             // the chr(13) substitution fixes the Bugs item #1421290.
  5963.             return strtr($sarray(')' => '\\)''(' => '\\(''\\' => '\\\\'chr(13=> '\r'));
  5964.         }
  5965.         
  5966.         /**
  5967.         * Format a date string for meta information
  5968.         * @param string $s date string to escape.
  5969.         * @return string escaped string.
  5970.         * @access protected
  5971.         */
  5972.         protected function _datastring($s{
  5973.             if ($this->encrypted{
  5974.                 $s $this->_RC4($this->_objectkey($this->n)$s);
  5975.             }
  5976.             return '('$this->_escape($s).')';
  5977.         }
  5978.         
  5979.         /**
  5980.         * Format a text string for meta information
  5981.         * @param string $s string to escape.
  5982.         * @return string escaped string.
  5983.         * @access protected
  5984.         */
  5985.         protected function _textstring($s{
  5986.             if ($this->isunicode{
  5987.                 //Convert string to UTF-16BE
  5988.                 $s $this->UTF8ToUTF16BE($strue);
  5989.             }
  5990.             return $this->_datastring($s);
  5991.         }
  5992.                 
  5993.         /**
  5994.         * Format a text string
  5995.         * @param string $s string to escape.
  5996.         * @return string escaped string.
  5997.         * @access protected
  5998.         */
  5999.         protected function _escapetext($s{
  6000.             if ($this->isunicode{
  6001.                 if (($this->CurrentFont['type'== 'core'OR ($this->CurrentFont['type'== 'TrueType'OR ($this->CurrentFont['type'== 'Type1')) {
  6002.                     $s $this->UTF8ToLatin1($s);
  6003.                 else {
  6004.                     //Convert string to UTF-16BE and reverse RTL language
  6005.                     $s $this->utf8StrRev($sfalse$this->tmprtl);
  6006.                 }
  6007.             }
  6008.             return $this->_escape($s);
  6009.         }
  6010.         
  6011.         /**
  6012.         * Output a stream.
  6013.         * @param string $s string to output.
  6014.         * @access protected
  6015.         */
  6016.         protected function _putstream($s{
  6017.             if ($this->encrypted{
  6018.                 $s $this->_RC4($this->_objectkey($this->n)$s);
  6019.             }
  6020.             $this->_out('stream');
  6021.             $this->_out($s);
  6022.             $this->_out('endstream');
  6023.         }
  6024.         
  6025.         /**
  6026.         * Output a string to the document.
  6027.         * @param string $s string to output.
  6028.         * @access protected
  6029.         */
  6030.         protected function _out($s{
  6031.             if ($this->state == 2{
  6032.                 if (isset($this->footerlen[$this->page]AND ($this->footerlen[$this->page0)) {
  6033.                     // puts data before page footer
  6034.                     $page substr($this->getPageBuffer($this->page)0-$this->footerlen[$this->page]);
  6035.                     $footer substr($this->getPageBuffer($this->page)-$this->footerlen[$this->page]);
  6036.                     $this->setPageBuffer($this->page$page.' '.$s."\n".$footer);
  6037.                 else {
  6038.                     $this->setPageBuffer($this->page$s."\n"true);
  6039.                 }
  6040.             else {
  6041.                 $this->setBuffer($s."\n");
  6042.             }
  6043.         }
  6044.         
  6045.          /**
  6046.          * Converts UTF-8 strings to codepoints array.<br>
  6047.          * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  6048.          * Based on: http://www.faqs.org/rfcs/rfc3629.html
  6049.          * <pre>
  6050.          *       Char. number range  |        UTF-8 octet sequence
  6051.          *       (hexadecimal)    |              (binary)
  6052.          *    --------------------+-----------------------------------------------
  6053.          *    0000 0000-0000 007F | 0xxxxxxx
  6054.          *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  6055.          *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  6056.          *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  6057.          *    ---------------------------------------------------------------------
  6058.          *
  6059.          *   ABFN notation:
  6060.          *   ---------------------------------------------------------------------
  6061.          *   UTF8-octets = *( UTF8-char )
  6062.          *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  6063.          *   UTF8-1      = %x00-7F
  6064.          *   UTF8-2      = %xC2-DF UTF8-tail
  6065.          *
  6066.          *   UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  6067.          *                 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  6068.          *   UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  6069.          *                 %xF4 %x80-8F 2( UTF8-tail )
  6070.          *   UTF8-tail   = %x80-BF
  6071.          *   ---------------------------------------------------------------------
  6072.          * </pre>
  6073.          * @param string $str string to process.
  6074.          * @return array containing codepoints (UTF-8 characters values)
  6075.          * @access protected
  6076.          * @author Nicola Asuni
  6077.          * @since 1.53.0.TC005 (2005-01-05)
  6078.          */
  6079.         protected function UTF8StringToArray($str{
  6080.             if (!$this->isunicode{
  6081.                 // split string into array of equivalent codes
  6082.                 $strarr array();
  6083.                 $strlen strlen($str);
  6084.                 for($i=0$i $strlen++$i{
  6085.                     $strarr[ord($str{$i});
  6086.                 }
  6087.                 return $strarr;
  6088.             }
  6089.             $unicode array()// array containing unicode values
  6090.             $bytes  array()// array containing single character byte sequences
  6091.             $numbytes  1// number of octetc needed to represent the UTF-8 character
  6092.             $str .= ''// force $str to be a string
  6093.             $length strlen($str);
  6094.             for($i 0$i $length++$i{
  6095.                 $char ord($str{$i})// get one string character at time
  6096.                 if (count($bytes== 0// get starting octect
  6097.                     if ($char <= 0x7F{
  6098.                         $unicode[$char// use the character "as is" because is ASCII
  6099.                         $numbytes 1;
  6100.                     elseif (($char >> 0x05== 0x06// 2 bytes character (0x06 = 110 BIN)
  6101.                         $bytes[($char 0xC0<< 0x06
  6102.                         $numbytes 2;
  6103.                     elseif (($char >> 0x04== 0x0E// 3 bytes character (0x0E = 1110 BIN)
  6104.                         $bytes[($char 0xE0<< 0x0C
  6105.                         $numbytes 3;
  6106.                     elseif (($char >> 0x03== 0x1E// 4 bytes character (0x1E = 11110 BIN)
  6107.                         $bytes[($char 0xF0<< 0x12
  6108.                         $numbytes 4;
  6109.                     else {
  6110.                         // use replacement character for other invalid sequences
  6111.                         $unicode[0xFFFD;
  6112.                         $bytes array();
  6113.                         $numbytes 1;
  6114.                     }
  6115.                 elseif (($char >> 0x06== 0x02// bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  6116.                     $bytes[$char 0x80;
  6117.                     if (count($bytes== $numbytes{
  6118.                         // compose UTF-8 bytes to a single unicode value
  6119.                         $char $bytes[0];
  6120.                         for($j 1$j $numbytes++$j{
  6121.                             $char += ($bytes[$j<< (($numbytes $j 10x06));
  6122.                         }
  6123.                         if ((($char >= 0xD800AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  6124.                             /* The definition of UTF-8 prohibits encoding character numbers between
  6125.                             U+D800 and U+DFFF, which are reserved for use with the UTF-16
  6126.                             encoding form (as surrogate pairs) and do not directly represent
  6127.                             characters. */
  6128.                             $unicode[0xFFFD// use replacement character
  6129.                         else {
  6130.                             $unicode[$char// add char to array
  6131.                         }
  6132.                         // reset data for next char
  6133.                         $bytes array()
  6134.                         $numbytes 1;
  6135.                     }
  6136.                 else {
  6137.                     // use replacement character for other invalid sequences
  6138.                     $unicode[0xFFFD;
  6139.                     $bytes array();
  6140.                     $numbytes 1;
  6141.                 }
  6142.             }
  6143.             return $unicode;
  6144.         }
  6145.         
  6146.         /**
  6147.          * Converts UTF-8 strings to UTF16-BE.<br>
  6148.          * @param string $str string to process.
  6149.          * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  6150.          * @return string 
  6151.          * @access protected
  6152.          * @author Nicola Asuni
  6153.          * @since 1.53.0.TC005 (2005-01-05)
  6154.          * @uses UTF8StringToArray(), arrUTF8ToUTF16BE()
  6155.          */
  6156.         protected function UTF8ToUTF16BE($str$setbom=true{
  6157.             if (!$this->isunicode{
  6158.                 return $str// string is not in unicode
  6159.             }
  6160.             $unicode $this->UTF8StringToArray($str)// array containing UTF-8 unicode values
  6161.             return $this->arrUTF8ToUTF16BE($unicode$setbom);
  6162.         }
  6163.         
  6164.         /**
  6165.          * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  6166.          * @param string $str string to process.
  6167.          * @return string 
  6168.          * @author Andrew Whitehead, Nicola Asuni
  6169.          * @access protected
  6170.          * @since 3.2.000 (2008-06-23)
  6171.          */
  6172.         protected function UTF8ToLatin1($str{
  6173.             global $utf8tolatin;
  6174.             if (!$this->isunicode{
  6175.                 return $str// string is not in unicode
  6176.             }
  6177.             $outstr ''// string to be returned
  6178.             $unicode $this->UTF8StringToArray($str)// array containing UTF-8 unicode values
  6179.             foreach ($unicode as $char{
  6180.                 if ($char 256{
  6181.                     $outstr .= chr($char);
  6182.                 elseif (array_key_exists($char$utf8tolatin)) {
  6183.                     // map from UTF-8
  6184.                     $outstr .= chr($utf8tolatin[$char]);
  6185.                 elseif ($char == 0xFFFD{
  6186.                     // skip
  6187.                 else {
  6188.                     $outstr .= '?';
  6189.                 }
  6190.             }
  6191.             return $outstr;
  6192.         }
  6193.  
  6194.         /**
  6195.          * Converts array of UTF-8 characters to UTF16-BE string.<br>
  6196.          * Based on: http://www.faqs.org/rfcs/rfc2781.html
  6197.           * <pre>
  6198.          *   Encoding UTF-16:
  6199.          * 
  6200.           *   Encoding of a single character from an ISO 10646 character value to
  6201.          *    UTF-16 proceeds as follows. Let U be the character number, no greater
  6202.          *    than 0x10FFFF.
  6203.          * 
  6204.          *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  6205.          *       terminate.
  6206.          * 
  6207.          *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  6208.          *       U' must be less than or equal to 0xFFFFF. That is, U' can be
  6209.          *       represented in 20 bits.
  6210.          * 
  6211.          *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  6212.          *       0xDC00, respectively. These integers each have 10 bits free to
  6213.          *       encode the character value, for a total of 20 bits.
  6214.          * 
  6215.          *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  6216.          *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
  6217.          *       bits of W2. Terminate.
  6218.          * 
  6219.          *    Graphically, steps 2 through 4 look like:
  6220.          *    U' = yyyyyyyyyyxxxxxxxxxx
  6221.          *    W1 = 110110yyyyyyyyyy
  6222.          *    W2 = 110111xxxxxxxxxx
  6223.          * </pre>
  6224.          * @param array $unicode array containing UTF-8 unicode values
  6225.          * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  6226.          * @return string 
  6227.          * @access protected
  6228.          * @author Nicola Asuni
  6229.          * @since 2.1.000 (2008-01-08)
  6230.          * @see UTF8ToUTF16BE()
  6231.          */
  6232.         protected function arrUTF8ToUTF16BE($unicode$setbom=true{
  6233.             $outstr ''// string to be returned
  6234.             if ($setbom{
  6235.                 $outstr .= "\xFE\xFF"// Byte Order Mark (BOM)
  6236.             }
  6237.             foreach ($unicode as $char{
  6238.                 if ($char == 0xFFFD{
  6239.                     $outstr .= "\xFF\xFD"// replacement character
  6240.                 elseif ($char 0x10000{
  6241.                     $outstr .= chr($char >> 0x08);
  6242.                     $outstr .= chr($char 0xFF);
  6243.                 else {
  6244.                     $char -= 0x10000;
  6245.                     $w1 0xD800 ($char >> 0x10);
  6246.                     $w2 0xDC00 ($char 0x3FF);    
  6247.                     $outstr .= chr($w1 >> 0x08);
  6248.                     $outstr .= chr($w1 0xFF);
  6249.                     $outstr .= chr($w2 >> 0x08);
  6250.                     $outstr .= chr($w2 0xFF);
  6251.                 }
  6252.             }
  6253.             return $outstr;
  6254.         }
  6255.         // ====================================================
  6256.         
  6257.         /**
  6258.           * Set header font.
  6259.          * @param array $font font
  6260.          * @since 1.1
  6261.          */
  6262.         public function setHeaderFont($font{
  6263.             $this->header_font = $font;
  6264.         }
  6265.         
  6266.         /**
  6267.           * Get header font.
  6268.           * @return array() 
  6269.          * @since 4.0.012 (2008-07-24)
  6270.          */
  6271.         public function getHeaderFont({
  6272.             return $this->header_font;
  6273.         }
  6274.         
  6275.         /**
  6276.           * Set footer font.
  6277.          * @param array $font font
  6278.          * @since 1.1
  6279.          */
  6280.         public function setFooterFont($font{
  6281.             $this->footer_font = $font;
  6282.         }
  6283.         
  6284.         /**
  6285.           * Get Footer font.
  6286.           * @return array() 
  6287.          * @since 4.0.012 (2008-07-24)
  6288.          */
  6289.         public function getFooterFont({
  6290.             return $this->footer_font;
  6291.         }
  6292.         
  6293.         /**
  6294.           * Set language array.
  6295.          * @param array $language 
  6296.          * @since 1.1
  6297.          */
  6298.         public function setLanguageArray($language{
  6299.             $this->l = $language;
  6300.             $this->rtl = $this->l['a_meta_dir']=='rtl' true false;
  6301.         }
  6302.         
  6303.         /**
  6304.          * Returns the PDF data.
  6305.          */
  6306.         public function getPDFData({
  6307.             if ($this->state < 3{
  6308.                 $this->Close();
  6309.             }
  6310.             return $this->buffer;
  6311.         }
  6312.                 
  6313.         /**
  6314.          * Output anchor link.
  6315.          * @param string $url link URL or internal link (i.e.: &lt;a href="#23"&gt;link to page 23&lt;/a&gt;)
  6316.          * @param string $name link name
  6317.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  6318.          * @param boolean $firstline if true prints only the first line and return the remaining string.
  6319.          * @param array $color array of RGB text color
  6320.          * @param string $style font style (U, D, B, I)
  6321.          * @return the number of cells used or the remaining text if $firstline = true;
  6322.          * @access public
  6323.          */
  6324.         public function addHtmlLink($url$name$fill=0$firstline=false$color=''$style=-1{
  6325.             if (!empty($urlAND ($url{0== '#')) {
  6326.                 // convert url to internal link
  6327.                 $page intval(substr($url1));
  6328.                 $url $this->AddLink();
  6329.                 $this->SetLink($url0$page);
  6330.             }
  6331.             // store current settings
  6332.             $prevcolor $this->fgcolor;
  6333.             $prevstyle $this->FontStyle;
  6334.             if (empty($color)) {
  6335.                 $this->SetTextColorArray($this->htmlLinkColorArray);
  6336.             else {
  6337.                 $this->SetTextColorArray($color);
  6338.             }
  6339.             if ($style == -1{
  6340.                 $this->SetFont(''$this->FontStyle.$this->htmlLinkFontStyle);
  6341.             else {
  6342.                 $this->SetFont(''$this->FontStyle.$style);
  6343.             }
  6344.             $ret $this->Write($this->lasth$name$url$fill''false0$firstline);
  6345.             // restore settings
  6346.             $this->SetFont(''$prevstyle);
  6347.             $this->SetTextColorArray($prevcolor);
  6348.             return $ret;
  6349.         }
  6350.         
  6351.         /**
  6352.          * Returns an associative array (keys: R,G,B) from an html color name or a six-digit or three-digit hexadecimal color representation (i.e. #3FE5AA or #7FF).
  6353.          * @param string $color html color
  6354.          * @return array 
  6355.          * @access public
  6356.          */        
  6357.         public function convertHTMLColorToDec($color='#000000'{
  6358.             global $webcolor;
  6359.             $color preg_replace('/[\s]*/'''$color)// remove extra spaces
  6360.             $color strtolower($color);
  6361.             // set default color to be returned in case of error
  6362.             $returncolor array ('R' => 0'G' => 0'B' => 0);
  6363.             if (empty($color)) {
  6364.                 return $returncolor;
  6365.             }
  6366.             if (substr($color03== 'rgb'{
  6367.                 $codes substr($color4);
  6368.                 $codes str_replace(')'''$codes);
  6369.                 $returncolor explode(','$codes3);
  6370.                 return $returncolor;
  6371.             }
  6372.             if (substr($color01!= '#'{
  6373.                 // decode color name
  6374.                 if (isset($webcolor[$color])) {
  6375.                     $color_code $webcolor[$color];
  6376.                 else {
  6377.                     return $returncolor;
  6378.                 }
  6379.             else {
  6380.                 $color_code substr($color1);
  6381.             }
  6382.             switch (strlen($color_code)) {
  6383.                 case 3{
  6384.                     // three-digit hexadecimal representation
  6385.                     $r substr($color_code01);
  6386.                     $g substr($color_code11);
  6387.                     $b substr($color_code21);
  6388.                     $returncolor['R'hexdec($r.$r);
  6389.                     $returncolor['G'hexdec($g.$g);
  6390.                     $returncolor['B'hexdec($b.$b);
  6391.                     break;
  6392.                 }
  6393.                 case 6{
  6394.                     // six-digit hexadecimal representation
  6395.                     $returncolor['R'hexdec(substr($color_code02));
  6396.                     $returncolor['G'hexdec(substr($color_code22));
  6397.                     $returncolor['B'hexdec(substr($color_code42));
  6398.                     break;
  6399.                 }
  6400.             }
  6401.             return $returncolor;
  6402.         }
  6403.         
  6404.         /**
  6405.          * Converts pixels to User's Units.
  6406.          * @param int $px pixels
  6407.          * @return float value in user's unit
  6408.          * @access public
  6409.          */
  6410.         public function pixelsToUnits($px{
  6411.             return ($px $this->k);
  6412.         }
  6413.             
  6414.         /**
  6415.          * Reverse function for htmlentities.
  6416.          * Convert entities in UTF-8.
  6417.          * @param $text_to_convert Text to convert.
  6418.          * @return string converted
  6419.          */
  6420.         public function unhtmlentities($text_to_convert{
  6421.             return html_entity_decode($text_to_convertENT_QUOTES$this->encoding);
  6422.         }
  6423.         
  6424.         // ENCRYPTION METHODS ----------------------------------
  6425.         // SINCE 2.0.000 (2008-01-02)
  6426.         
  6427.         /**
  6428.         * Compute encryption key depending on object number where the encrypted data is stored
  6429.         * @param int $n object number
  6430.         * @since 2.0.000 (2008-01-02)
  6431.         */
  6432.         protected function _objectkey($n{
  6433.             return substr($this->_md5_16($this->encryption_key.pack('VXxx'$n))010);
  6434.         }
  6435.         
  6436.         /**
  6437.          * Put encryption on PDF document.
  6438.          * @since 2.0.000 (2008-01-02)
  6439.          */
  6440.         protected function _putencryption({
  6441.             $this->_out('/Filter /Standard');
  6442.             $this->_out('/V 1');
  6443.             $this->_out('/R 2');
  6444.             $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  6445.             $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  6446.             $this->_out('/P '.$this->Pvalue);
  6447.         }
  6448.         
  6449.         /**
  6450.         * Returns the input text exrypted using RC4 algorithm and the specified key.
  6451.         * RC4 is the standard encryption algorithm used in PDF format
  6452.         * @param string $key encryption key
  6453.         * @param String $text input text to be encrypted
  6454.         * @return String encrypted text
  6455.         * @since 2.0.000 (2008-01-02)
  6456.         * @author Klemen Vodopivec
  6457.         */
  6458.         protected function _RC4($key$text{
  6459.             if ($this->last_rc4_key != $key{
  6460.                 $k str_repeat($key((256 strlen($key)) 1));
  6461.                 $rc4 range(0255);
  6462.                 $j 0;
  6463.                 for ($i 0$i 256++$i{
  6464.                     $t $rc4[$i];
  6465.                     $j ($j $t ord($k{$i})) 256;
  6466.                     $rc4[$i$rc4[$j];
  6467.                     $rc4[$j$t;
  6468.                 }
  6469.                 $this->last_rc4_key = $key;
  6470.                 $this->last_rc4_key_c = $rc4;
  6471.             else {
  6472.                 $rc4 $this->last_rc4_key_c;
  6473.             }
  6474.             $len strlen($text);
  6475.             $a 0;
  6476.             $b 0;
  6477.             $out '';
  6478.             for ($i 0$i $len++$i{
  6479.                 $a ($a 1256;
  6480.                 $t $rc4[$a];
  6481.                 $b ($b $t256;
  6482.                 $rc4[$a$rc4[$b];
  6483.                 $rc4[$b$t;
  6484.                 $k $rc4[($rc4[$a$rc4[$b]256];
  6485.                 $out .= chr(ord($text{$i}$k);
  6486.             }
  6487.             return $out;
  6488.         }
  6489.         
  6490.         /**
  6491.         * Encrypts a string using MD5 and returns it's value as a binary string.
  6492.         * @param string $str input string
  6493.         * @return String MD5 encrypted binary string
  6494.         * @since 2.0.000 (2008-01-02)
  6495.         * @author Klemen Vodopivec
  6496.         */
  6497.         protected function _md5_16($str{
  6498.             return pack('H*'md5($str));
  6499.         }
  6500.         
  6501.         /**
  6502.         * Compute O value (used for RC4 encryption)
  6503.         * @param String $user_pass user password
  6504.         * @param String $owner_pass user password
  6505.         * @return String O value
  6506.         * @since 2.0.000 (2008-01-02)
  6507.         * @author Klemen Vodopivec
  6508.         */
  6509.         protected function _Ovalue($user_pass$owner_pass{
  6510.             $tmp $this->_md5_16($owner_pass);
  6511.             $owner_RC4_key substr($tmp05);
  6512.             return $this->_RC4($owner_RC4_key$user_pass);
  6513.         }
  6514.         
  6515.         /**
  6516.         * Compute U value (used for RC4 encryption)
  6517.         * @return String U value
  6518.         * @since 2.0.000 (2008-01-02)
  6519.         * @author Klemen Vodopivec
  6520.         */
  6521.         protected function _Uvalue({
  6522.             return $this->_RC4($this->encryption_key$this->padding);
  6523.         }
  6524.         
  6525.         /**
  6526.         * Compute encryption key
  6527.         * @param String $user_pass user password
  6528.         * @param String $owner_pass user password
  6529.         * @param String $protection protection type
  6530.         * @since 2.0.000 (2008-01-02)
  6531.         * @author Klemen Vodopivec
  6532.         */
  6533.         protected function _generateencryptionkey($user_pass$owner_pass$protection{
  6534.             // Pad passwords
  6535.             $user_pass substr($user_pass.$this->padding032);
  6536.             $owner_pass substr($owner_pass.$this->padding032);
  6537.             // Compute O value
  6538.             $this->Ovalue = $this->_Ovalue($user_pass$owner_pass);
  6539.             // Compute encyption key
  6540.             $tmp $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
  6541.             $this->encryption_key = substr($tmp05);
  6542.             // Compute U value
  6543.             $this->Uvalue = $this->_Uvalue();
  6544.             // Compute P value
  6545.             $this->Pvalue = -(($protection^2551);
  6546.         }
  6547.         
  6548.         /**
  6549.         * Set document protection
  6550.         * The permission array is composed of values taken from the following ones:
  6551.         * - copy: copy text and images to the clipboard
  6552.         * - print: print the document
  6553.         * - modify: modify it (except for annotations and forms)
  6554.         * - annot-forms: add annotations and forms
  6555.         * Remark: the protection against modification is for people who have the full Acrobat product.
  6556.         * If you don't set any password, the document will open as usual. If you set a user password, the PDF viewer will ask for it before displaying the document. The master password, if different from the user one, can be used to get full access.
  6557.         * Note: protecting a document requires to encrypt it, which increases the processing time a lot. This can cause a PHP time-out in some cases, especially if the document contains images or fonts.
  6558.         * @param Array $permissions the set of permissions. Empty by default (only viewing is allowed). (print, modify, copy, annot-forms)
  6559.         * @param String $user_pass user password. Empty by default.
  6560.         * @param String $owner_pass owner password. If not specified, a random value is used.
  6561.         * @since 2.0.000 (2008-01-02)
  6562.         * @author Klemen Vodopivec
  6563.         */
  6564.         public function SetProtection($permissions=array()$user_pass=''$owner_pass=null{
  6565.             $options array('print' => 4'modify' => 8'copy' => 16'annot-forms' => 32);
  6566.             $protection 192;
  6567.             foreach ($permissions as $permission{
  6568.                 if (!isset($options[$permission])) {
  6569.                     $this->Error('Incorrect permission: '.$permission);
  6570.                 }
  6571.                 $protection += $options[$permission];
  6572.             }
  6573.             if ($owner_pass === null{
  6574.                 $owner_pass uniqid(rand());
  6575.             }
  6576.             $this->encrypted = true;
  6577.             $this->_generateencryptionkey($user_pass$owner_pass$protection);
  6578.         }
  6579.         
  6580.         // END OF ENCRYPTION FUNCTIONS -------------------------
  6581.         
  6582.         // START TRANSFORMATIONS SECTION -----------------------
  6583.         
  6584.         /**
  6585.         * Starts a 2D tranformation saving current graphic state.
  6586.         * This function must be called before scaling, mirroring, translation, rotation and skewing.
  6587.         * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  6588.         * @since 2.1.000 (2008-01-07)
  6589.         * @see StartTransform(), StopTransform()
  6590.         */
  6591.         public function StartTransform({
  6592.             $this->_out('q');
  6593.             $this->transfmrk[$this->page][$this->pagelen[$this->page];
  6594.         }
  6595.         
  6596.         /**
  6597.         * Stops a 2D tranformation restoring previous graphic state.
  6598.         * This function must be called after scaling, mirroring, translation, rotation and skewing.
  6599.         * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  6600.         * @since 2.1.000 (2008-01-07)
  6601.         * @see StartTransform(), StopTransform()
  6602.         */
  6603.         public function StopTransform({
  6604.             $this->_out('Q');
  6605.             if (isset($this->transfmatrix)) {
  6606.                 array_pop($this->transfmatrix);
  6607.             }
  6608.             array_pop($this->transfmrk[$this->page]);
  6609.         }
  6610.         /**
  6611.         * Horizontal Scaling.
  6612.         * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  6613.         * @param int $x abscissa of the scaling center. Default is current x position
  6614.         * @param int $y ordinate of the scaling center. Default is current y position
  6615.         * @since 2.1.000 (2008-01-07)
  6616.         * @see StartTransform(), StopTransform()
  6617.         */
  6618.         public function ScaleX($s_x$x=''$y=''{
  6619.             $this->Scale($s_x100$x$y);
  6620.         }
  6621.         
  6622.         /**
  6623.         * Vertical Scaling.
  6624.         * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  6625.         * @param int $x abscissa of the scaling center. Default is current x position
  6626.         * @param int $y ordinate of the scaling center. Default is current y position
  6627.         * @since 2.1.000 (2008-01-07)
  6628.         * @see StartTransform(), StopTransform()
  6629.         */
  6630.         public function ScaleY($s_y$x=''$y=''{
  6631.             $this->Scale(100$s_y$x$y);
  6632.         }
  6633.         
  6634.         /**
  6635.         * Vertical and horizontal proportional Scaling.
  6636.         * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  6637.         * @param int $x abscissa of the scaling center. Default is current x position
  6638.         * @param int $y ordinate of the scaling center. Default is current y position
  6639.         * @since 2.1.000 (2008-01-07)
  6640.         * @see StartTransform(), StopTransform()
  6641.         */
  6642.         public function ScaleXY($s$x=''$y=''{
  6643.             $this->Scale($s$s$x$y);
  6644.         }
  6645.         
  6646.         /**
  6647.         * Vertical and horizontal non-proportional Scaling.
  6648.         * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  6649.         * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  6650.         * @param int $x abscissa of the scaling center. Default is current x position
  6651.         * @param int $y ordinate of the scaling center. Default is current y position
  6652.         * @since 2.1.000 (2008-01-07)
  6653.         * @see StartTransform(), StopTransform()
  6654.         */
  6655.         public function Scale($s_x$s_y$x=''$y=''{
  6656.             if ($x === ''{
  6657.                 $x $this->x;
  6658.             }
  6659.             if ($y === ''{
  6660.                 $y $this->y;
  6661.             }
  6662.             if ($this->rtl{
  6663.                 $x $this->w - $x;
  6664.             }
  6665.             if (($s_x == 0OR ($s_y == 0)) {
  6666.                 $this->Error('Please do not use values equal to zero for scaling');
  6667.             }
  6668.             $y ($this->h - $y$this->k;
  6669.             $x *= $this->k;
  6670.             //calculate elements of transformation matrix
  6671.             $s_x /= 100;
  6672.             $s_y /= 100;
  6673.             $tm[0$s_x;
  6674.             $tm[10;
  6675.             $tm[20;
  6676.             $tm[3$s_y;
  6677.             $tm[4$x ($s_x);
  6678.             $tm[5$y ($s_y);
  6679.             //scale the coordinate system
  6680.             $this->Transform($tm);
  6681.         }
  6682.         
  6683.         /**
  6684.         * Horizontal Mirroring.
  6685.         * @param int $x abscissa of the point. Default is current x position
  6686.         * @since 2.1.000 (2008-01-07)
  6687.         * @see StartTransform(), StopTransform()
  6688.         */
  6689.         public function MirrorH($x=''{
  6690.             $this->Scale(-100100$x);
  6691.         }
  6692.         
  6693.         /**
  6694.         * Verical Mirroring.
  6695.         * @param int $y ordinate of the point. Default is current y position
  6696.         * @since 2.1.000 (2008-01-07)
  6697.         * @see StartTransform(), StopTransform()
  6698.         */
  6699.         public function MirrorV($y=''{
  6700.             $this->Scale(100-100''$y);
  6701.         }
  6702.         
  6703.         /**
  6704.         * Point reflection mirroring.
  6705.         * @param int $x abscissa of the point. Default is current x position
  6706.         * @param int $y ordinate of the point. Default is current y position
  6707.         * @since 2.1.000 (2008-01-07)
  6708.         * @see StartTransform(), StopTransform()
  6709.         */
  6710.         public function MirrorP($x='',$y=''{
  6711.             $this->Scale(-100-100$x$y);
  6712.         }
  6713.         
  6714.         /**
  6715.         * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  6716.         * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  6717.         * @param int $x abscissa of the point. Default is current x position
  6718.         * @param int $y ordinate of the point. Default is current y position
  6719.         * @since 2.1.000 (2008-01-07)
  6720.         * @see StartTransform(), StopTransform()
  6721.         */
  6722.         public function MirrorL($angle=0$x='',$y=''{
  6723.             $this->Scale(-100100$x$y);
  6724.             $this->Rotate(-2*($angle-90)$x$y);
  6725.         }
  6726.         
  6727.         /**
  6728.         * Translate graphic object horizontally.
  6729.         * @param int $t_x movement to the right (or left for RTL)
  6730.         * @since 2.1.000 (2008-01-07)
  6731.         * @see StartTransform(), StopTransform()
  6732.         */
  6733.         public function TranslateX($t_x{
  6734.             $this->Translate($t_x0);
  6735.         }
  6736.         
  6737.         /**
  6738.         * Translate graphic object vertically.
  6739.         * @param int $t_y movement to the bottom
  6740.         * @since 2.1.000 (2008-01-07)
  6741.         * @see StartTransform(), StopTransform()
  6742.         */
  6743.         public function TranslateY($t_y{
  6744.             $this->Translate(0$t_y);
  6745.         }
  6746.         
  6747.         /**
  6748.         * Translate graphic object horizontally and vertically.
  6749.         * @param int $t_x movement to the right
  6750.         * @param int $t_y movement to the bottom
  6751.         * @since 2.1.000 (2008-01-07)
  6752.         * @see StartTransform(), StopTransform()
  6753.         */
  6754.         public function Translate($t_x$t_y{
  6755.             if ($this->rtl{
  6756.                 $t_x = -$t_x;
  6757.             }
  6758.             //calculate elements of transformation matrix
  6759.             $tm[01;
  6760.             $tm[10;
  6761.             $tm[20;
  6762.             $tm[31;
  6763.             $tm[4$t_x $this->k;
  6764.             $tm[5= -$t_y $this->k;
  6765.             //translate the coordinate system
  6766.             $this->Transform($tm);
  6767.         }
  6768.         
  6769.         /**
  6770.         * Rotate object.
  6771.         * @param float $angle angle in degrees for counter-clockwise rotation
  6772.         * @param int $x abscissa of the rotation center. Default is current x position
  6773.         * @param int $y ordinate of the rotation center. Default is current y position
  6774.         * @since 2.1.000 (2008-01-07)
  6775.         * @see StartTransform(), StopTransform()
  6776.         */
  6777.         public function Rotate($angle$x=''$y=''{
  6778.             if ($x === ''{
  6779.                 $x $this->x;
  6780.             }
  6781.             if ($y === ''{
  6782.                 $y $this->y;
  6783.             }
  6784.             if ($this->rtl{
  6785.                 $x $this->w - $x;
  6786.                 $angle = -$angle;
  6787.             }
  6788.             $y ($this->h - $y$this->k;
  6789.             $x *= $this->k;
  6790.             //calculate elements of transformation matrix
  6791.             $tm[0cos(deg2rad($angle));
  6792.             $tm[1sin(deg2rad($angle));
  6793.             $tm[2= -$tm[1];
  6794.             $tm[3$tm[0];
  6795.             $tm[4$x ($tm[1$y($tm[0$x);
  6796.             $tm[5$y ($tm[0$y($tm[1$x);
  6797.             //rotate the coordinate system around ($x,$y)
  6798.             $this->Transform($tm);
  6799.         }
  6800.         
  6801.         /**
  6802.         * Skew horizontally.
  6803.         * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  6804.         * @param int $x abscissa of the skewing center. default is current x position
  6805.         * @param int $y ordinate of the skewing center. default is current y position
  6806.         * @since 2.1.000 (2008-01-07)
  6807.         * @see StartTransform(), StopTransform()
  6808.         */
  6809.         public function SkewX($angle_x$x=''$y=''{
  6810.             $this->Skew($angle_x0$x$y);
  6811.         }
  6812.         
  6813.         /**
  6814.         * Skew vertically.
  6815.         * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  6816.         * @param int $x abscissa of the skewing center. default is current x position
  6817.         * @param int $y ordinate of the skewing center. default is current y position
  6818.         * @since 2.1.000 (2008-01-07)
  6819.         * @see StartTransform(), StopTransform()
  6820.         */
  6821.         public function SkewY($angle_y$x=''$y=''{
  6822.             $this->Skew(0$angle_y$x$y);
  6823.         }
  6824.         
  6825.         /**
  6826.         * Skew.
  6827.         * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  6828.         * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  6829.         * @param int $x abscissa of the skewing center. default is current x position
  6830.         * @param int $y ordinate of the skewing center. default is current y position
  6831.         * @since 2.1.000 (2008-01-07)
  6832.         * @see StartTransform(), StopTransform()
  6833.         */
  6834.         public function Skew($angle_x$angle_y$x=''$y=''{
  6835.             if ($x === ''{
  6836.                 $x $this->x;
  6837.             }
  6838.             if ($y === ''{
  6839.                 $y $this->y;
  6840.             }
  6841.             if ($this->rtl{
  6842.                 $x $this->w - $x;
  6843.                 $angle_x = -$angle_x;
  6844.             }
  6845.             if (($angle_x <= -90OR ($angle_x >= 90OR ($angle_y <= -90OR ($angle_y >= 90)) {
  6846.                 $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  6847.             }
  6848.             $x *= $this->k;
  6849.             $y ($this->h - $y$this->k;
  6850.             //calculate elements of transformation matrix
  6851.             $tm[01;
  6852.             $tm[1tan(deg2rad($angle_y));
  6853.             $tm[2tan(deg2rad($angle_x));
  6854.             $tm[31;
  6855.             $tm[4= -$tm[2$y;
  6856.             $tm[5= -$tm[1$x;
  6857.             //skew the coordinate system
  6858.             $this->Transform($tm);
  6859.         }
  6860.         
  6861.         /**
  6862.         * Apply graphic transformations.
  6863.         * @since 2.1.000 (2008-01-07)
  6864.         * @see StartTransform(), StopTransform()
  6865.         */
  6866.         protected function Transform($tm{
  6867.             $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f cm'$tm[0]$tm[1]$tm[2]$tm[3]$tm[4]$tm[5]));
  6868.             // store transformation matrix
  6869.             $this->transfmatrix[array('a' => $tm[0]'b' => $tm[1]'c' => $tm[2]'d' => $tm[3]'e' => $tm[4]'f' => $tm[5]);
  6870.             // update tranformation mark
  6871.             if (end($this->transfmrk[$this->page]!== false{
  6872.                 $key key($this->transfmrk[$this->page]);
  6873.                 $this->transfmrk[$this->page][$key$this->pagelen[$this->page];
  6874.             }
  6875.         }
  6876.         
  6877.         // END TRANSFORMATIONS SECTION -------------------------
  6878.         
  6879.         
  6880.         // START GRAPHIC FUNCTIONS SECTION ---------------------
  6881.         // The following section is based on the code provided by David Hernandez Sanz
  6882.         
  6883.         /**
  6884.         * Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
  6885.         * @param float $width The width.
  6886.         * @since 1.0
  6887.         * @see Line(), Rect(), Cell(), MultiCell()
  6888.         */
  6889.         public function SetLineWidth($width{
  6890.             //Set line width
  6891.             $this->LineWidth = $width;
  6892.             $this->linestyleWidth = sprintf('%.2f w'($width $this->k));
  6893.             $this->_out($this->linestyleWidth);
  6894.         }
  6895.         
  6896.         /**
  6897.         * Returns the current the line width.
  6898.         * @return int Line width
  6899.         * @since 2.1.000 (2008-01-07)
  6900.         * @see Line(), SetLineWidth()
  6901.         */
  6902.         public function GetLineWidth({
  6903.             return $this->LineWidth;
  6904.         }
  6905.         
  6906.         /**
  6907.         * Set line style.
  6908.         * @param array $style Line style. Array with keys among the following:
  6909.         *  <ul>
  6910.         *      <li>width (float): Width of the line in user units.</li>
  6911.         *      <li>cap (string): Type of cap to put on the line. Possible values are:
  6912.         *  butt, round, square. The difference between "square" and "butt" is that
  6913.         *  "square" projects a flat end past the end of the line.</li>
  6914.         *      <li>join (string): Type of join. Possible values are: miter, round,
  6915.         *  bevel.</li>
  6916.         *      <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  6917.         *  series of length values, which are the lengths of the on and off dashes.
  6918.         *  For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  6919.         *  1 off, 2 on, 1 off, ...</li>
  6920.         *      <li>phase (integer): Modifier on the dash pattern which is used to shift
  6921.         *  the point at which the pattern starts.</li>
  6922.         *      <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
  6923.         *  </ul>
  6924.         * @access public
  6925.         * @since 2.1.000 (2008-01-08)
  6926.         */
  6927.         public function SetLineStyle($style{
  6928.             extract($style);
  6929.             if (isset($width)) {
  6930.                 $width_prev $this->LineWidth;
  6931.                 $this->SetLineWidth($width);
  6932.                 $this->LineWidth = $width_prev;
  6933.             }
  6934.             if (isset($cap)) {
  6935.                 $ca array('butt' => 0'round'=> 1'square' => 2);
  6936.                 if (isset($ca[$cap])) {
  6937.                     $this->linestyleCap = $ca[$cap].' J';
  6938.                     $this->_out($this->linestyleCap);
  6939.                 }
  6940.             }
  6941.             if (isset($join)) {
  6942.                 $ja array('miter' => 0'round' => 1'bevel' => 2);
  6943.                 if (isset($ja[$join])) {
  6944.                     $this->linestyleJoin = $ja[$join].' j';
  6945.                     $this->_out($this->linestyleJoin);
  6946.                 }
  6947.             }
  6948.             if (isset($dash)) {
  6949.                 $dash_string '';
  6950.                 if ($dash{
  6951.                     if (ereg('^.+,'$dash)) {
  6952.                         $tab explode(','$dash);
  6953.                     else {
  6954.                         $tab array($dash);
  6955.                     }
  6956.                     $dash_string '';
  6957.                     foreach ($tab as $i => $v{
  6958.                         if ($i{
  6959.                             $dash_string .= ' ';
  6960.                         }
  6961.                         $dash_string .= sprintf("%.2f"$v);
  6962.                     }
  6963.                 }
  6964.                 if (!isset($phaseOR !$dash{
  6965.                     $phase 0;
  6966.                 }
  6967.                 $this->linestyleDash = sprintf("[%s] %.2f d"$dash_string$phase);
  6968.                 $this->_out($this->linestyleDash);
  6969.             }
  6970.             if (isset($color)) {
  6971.                 $this->SetDrawColorArray($color);
  6972.             }
  6973.         }
  6974.         
  6975.         /*
  6976.         * Set a draw point.
  6977.         * @param float $x Abscissa of point.
  6978.         * @param float $y Ordinate of point.
  6979.         * @access protected
  6980.         * @since 2.1.000 (2008-01-08)
  6981.         */
  6982.         protected function _outPoint($x$y{
  6983.             if ($this->rtl{
  6984.                 $x $this->w - $x;
  6985.             }
  6986.             $this->_out(sprintf("%.2f %.2f m"$x $this->k($this->h - $y$this->k));
  6987.         }
  6988.         
  6989.         /*
  6990.         * Draws a line from last draw point.
  6991.         * @param float $x Abscissa of end point.
  6992.         * @param float $y Ordinate of end point.
  6993.         * @access protected
  6994.         * @since 2.1.000 (2008-01-08)
  6995.         */
  6996.         protected function _outLine($x$y{
  6997.             if ($this->rtl{
  6998.                 $x $this->w - $x;
  6999.             }
  7000.             $this->_out(sprintf("%.2f %.2f l"$x $this->k($this->h - $y$this->k));
  7001.         }
  7002.         
  7003.         /**
  7004.         * Draws a rectangle.
  7005.         * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  7006.         * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  7007.         * @param float $w Width.
  7008.         * @param float $h Height.
  7009.         * @param string $op options
  7010.         * @access protected
  7011.         * @since 2.1.000 (2008-01-08)
  7012.         */
  7013.         protected function _outRect($x$y$w$h$op{
  7014.             if ($this->rtl{
  7015.                 $x $this->w - $x $w;
  7016.             }
  7017.             $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s'$x*$this->k($this->h-$y)*$this->k$w*$this->k-$h*$this->k$op));
  7018.         }
  7019.         
  7020.         /*
  7021.         * Draws a Bezier curve from last draw point.
  7022.         * The Bezier curve is a tangent to the line between the control points at either end of the curve.
  7023.         * @param float $x1 Abscissa of control point 1.
  7024.         * @param float $y1 Ordinate of control point 1.
  7025.         * @param float $x2 Abscissa of control point 2.
  7026.         * @param float $y2 Ordinate of control point 2.
  7027.         * @param float $x3 Abscissa of end point.
  7028.         * @param float $y3 Ordinate of end point.
  7029.         * @access protected
  7030.         * @since 2.1.000 (2008-01-08)
  7031.         */
  7032.         protected function _outCurve($x1$y1$x2$y2$x3$y3{
  7033.             if ($this->rtl{
  7034.                 $x1 $this->w - $x1;
  7035.                 $x2 $this->w - $x2;
  7036.                 $x3 $this->w - $x3;
  7037.             }
  7038.             $this->_out(sprintf("%.2f %.2f %.2f %.2f %.2f %.2f c"$x1 $this->k($this->h - $y1$this->k$x2 $this->k($this->h - $y2$this->k$x3 $this->k($this->h - $y3$this->k));
  7039.         }
  7040.         
  7041.         /**
  7042.         * Draws a line between two points.
  7043.         * @param float $x1 Abscissa of first point.
  7044.         * @param float $y1 Ordinate of first point.
  7045.         * @param float $x2 Abscissa of second point.
  7046.         * @param float $y2 Ordinate of second point.
  7047.         * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7048.         * @access public
  7049.         * @since 1.0
  7050.         * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  7051.         */
  7052.         public function Line($x1$y1$x2$y2$style=array()) {
  7053.             if ($style{
  7054.                 $this->SetLineStyle($style);
  7055.             }
  7056.             $this->_outPoint($x1$y1);
  7057.             $this->_outLine($x2$y2);
  7058.             $this->_out(' S');
  7059.         }
  7060.         
  7061.         /**
  7062.         * Draws a rectangle.
  7063.         * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  7064.         * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  7065.         * @param float $w Width.
  7066.         * @param float $h Height.
  7067.         * @param string $style Style of rendering. Possible values are:
  7068.         *  <ul>
  7069.         *      <li>D or empty string: Draw (default).</li>
  7070.         *      <li>F: Fill.</li>
  7071.         *      <li>DF or FD: Draw and fill.</li>
  7072.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7073.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7074.         *  </ul>
  7075.         * @param array $border_style Border style of rectangle. Array with keys among the following:
  7076.         *  <ul>
  7077.         *      <li>all: Line style of all borders. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7078.         *      <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7079.         *  </ul>
  7080.         *  If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  7081.         * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7082.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  7083.         * @access public
  7084.         * @since 1.0
  7085.         * @see SetLineStyle()
  7086.         */
  7087.         public function Rect($x$y$w$h$style=''$border_style=array()$fill_color=array()) {
  7088.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7089.                 $this->SetFillColorArray($fill_color);
  7090.             }
  7091.             switch ($style{
  7092.                 case 'F'{
  7093.                     $op 'f';
  7094.                     $border_style array();
  7095.                     $this->_outRect($x$y$w$h$op);
  7096.                     break;
  7097.                 }
  7098.                 case 'DF':
  7099.                 case 'FD'{
  7100.                     if ((!$border_styleOR (isset($border_style['all']))) {
  7101.                         $op 'B';
  7102.                         if (isset($border_style['all'])) {
  7103.                             $this->SetLineStyle($border_style['all']);
  7104.                             $border_style array();
  7105.                         }
  7106.                     else {
  7107.                         $op 'f';
  7108.                     }
  7109.                     $this->_outRect($x$y$w$h$op);
  7110.                     break;
  7111.                 }
  7112.                 case 'CNZ'{
  7113.                     $op 'W n';
  7114.                     $this->_outRect($x$y$w$h$op);
  7115.                     break;
  7116.                 }
  7117.                 case 'CEO'{
  7118.                     $op 'W* n';
  7119.                     $this->_outRect($x$y$w$h$op);
  7120.                     break;
  7121.                 }
  7122.                 default{
  7123.                     $op 'S';
  7124.                     if ((!$border_styleOR (isset($border_style['all']))) {
  7125.                         if (isset($border_style['all']AND $border_style['all']{
  7126.                             $this->SetLineStyle($border_style['all']);
  7127.                             $border_style array();
  7128.                         }
  7129.                         $this->_outRect($x$y$w$h$op);
  7130.                     }
  7131.                     break;
  7132.                 }
  7133.             }
  7134.             if ($border_style{
  7135.                 $border_style2 array();
  7136.                 foreach ($border_style as $line => $value{
  7137.                     $lenght strlen($line);
  7138.                     for ($i 0$i $lenght++$i{
  7139.                         $border_style2[$line[$i]] $value;
  7140.                     }
  7141.                 }
  7142.                 $border_style $border_style2;
  7143.                 if (isset($border_style['L']AND $border_style['L']{
  7144.                     $this->Line($x$y$x$y $h$border_style['L']);
  7145.                 }
  7146.                 if (isset($border_style['T']AND $border_style['T']{
  7147.                     $this->Line($x$y$x $w$y$border_style['T']);
  7148.                 }
  7149.                 if (isset($border_style['R']AND $border_style['R']{
  7150.                     $this->Line($x $w$y$x $w$y $h$border_style['R']);
  7151.                 }
  7152.                 if (isset($border_style['B']AND $border_style['B']{
  7153.                     $this->Line($x$y $h$x $w$y $h$border_style['B']);
  7154.                 }
  7155.             }
  7156.         }
  7157.         
  7158.         
  7159.         /**
  7160.         * Draws a Bezier curve.
  7161.         * The Bezier curve is a tangent to the line between the control points at
  7162.         * either end of the curve.
  7163.         * @param float $x0 Abscissa of start point.
  7164.         * @param float $y0 Ordinate of start point.
  7165.         * @param float $x1 Abscissa of control point 1.
  7166.         * @param float $y1 Ordinate of control point 1.
  7167.         * @param float $x2 Abscissa of control point 2.
  7168.         * @param float $y2 Ordinate of control point 2.
  7169.         * @param float $x3 Abscissa of end point.
  7170.         * @param float $y3 Ordinate of end point.
  7171.         * @param string $style Style of rendering. Possible values are:
  7172.         *  <ul>
  7173.         *      <li>D or empty string: Draw (default).</li>
  7174.         *      <li>F: Fill.</li>
  7175.         *      <li>DF or FD: Draw and fill.</li>
  7176.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7177.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7178.         *  </ul>
  7179.         * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7180.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  7181.         * @access public
  7182.         * @see SetLineStyle()
  7183.         * @since 2.1.000 (2008-01-08)
  7184.         */
  7185.         public function Curve($x0$y0$x1$y1$x2$y2$x3$y3$style=''$line_style=array()$fill_color=array()) {
  7186.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7187.                 $this->SetFillColorArray($fill_color);
  7188.             }
  7189.             switch ($style{
  7190.                 case 'F'{
  7191.                     $op 'f';
  7192.                     $line_style array();
  7193.                     break;
  7194.                 }
  7195.                 case 'FD'
  7196.                 case 'DF'{
  7197.                     $op 'B';
  7198.                     break;
  7199.                 }
  7200.                 case 'CNZ'{
  7201.                     $op 'W n';
  7202.                     break;
  7203.                 }
  7204.                 case 'CEO'{
  7205.                     $op 'W* n';
  7206.                     break;
  7207.                 }
  7208.                 default{
  7209.                     $op 'S';
  7210.                     break;
  7211.                 }
  7212.             }
  7213.             if ($line_style{
  7214.                 $this->SetLineStyle($line_style);
  7215.             }
  7216.             $this->_outPoint($x0$y0);
  7217.             $this->_outCurve($x1$y1$x2$y2$x3$y3);
  7218.             $this->_out($op);
  7219.         }
  7220.         
  7221.         /**
  7222.         * Draws a poly-Bezier curve.
  7223.         * Each Bezier curve segment is a tangent to the line between the control points at
  7224.         * either end of the curve.
  7225.         * @param float $x0 Abscissa of start point.
  7226.         * @param float $y0 Ordinate of start point.
  7227.         * @param float $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  7228.         * @param string $style Style of rendering. Possible values are:
  7229.         *  <ul>
  7230.         *      <li>D or empty string: Draw (default).</li>
  7231.         *      <li>F: Fill.</li>
  7232.         *      <li>DF or FD: Draw and fill.</li>
  7233.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7234.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7235.         *  </ul>
  7236.         * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7237.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  7238.         * @access public
  7239.         * @see SetLineStyle()
  7240.         * @since 3.0008 (2008-05-12)
  7241.         */
  7242.         public function Polycurve($x0$y0$segments$style=''$line_style=array()$fill_color=array()) {
  7243.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7244.                 $this->SetFillColorArray($fill_color);
  7245.             }
  7246.             switch ($style{
  7247.                 case 'F'{
  7248.                     $op 'f';
  7249.                     $line_style array();
  7250.                     break;
  7251.                 }
  7252.                 case 'FD':
  7253.                 case 'DF'{
  7254.                     $op 'B';
  7255.                     break;
  7256.                 }
  7257.                 case 'CNZ'{
  7258.                     $op 'W n';
  7259.                     break;
  7260.                 }
  7261.                 case 'CEO'{
  7262.                     $op 'W* n';
  7263.                     break;
  7264.                 }
  7265.                 default{
  7266.                     $op 'S';
  7267.                     break;
  7268.                 }
  7269.             }
  7270.             if ($line_style{
  7271.                 $this->SetLineStyle($line_style);
  7272.             }
  7273.             $this->_outPoint($x0$y0);
  7274.             foreach ($segments as $segment{
  7275.                 list($x1$y1$x2$y2$x3$y3$segment;
  7276.                 $this->_outCurve($x1$y1$x2$y2$x3$y3);
  7277.             }    
  7278.             $this->_out($op);
  7279.         }
  7280.         
  7281.         /**
  7282.         * Draws an ellipse.
  7283.         * An ellipse is formed from n Bezier curves.
  7284.         * @param float $x0 Abscissa of center point.
  7285.         * @param float $y0 Ordinate of center point.
  7286.         * @param float $rx Horizontal radius.
  7287.         * @param float $ry Vertical radius (if ry = 0 then is a circle, see {@link Circle Circle}). Default value: 0.
  7288.         * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  7289.         * @param float $astart: Angle start of draw line. Default value: 0.
  7290.         * @param float $afinish: Angle finish of draw line. Default value: 360.
  7291.         * @param string $style Style of rendering. Possible values are:
  7292.         *  <ul>
  7293.         *      <li>D or empty string: Draw (default).</li>
  7294.         *      <li>F: Fill.</li>
  7295.         *      <li>DF or FD: Draw and fill.</li>
  7296.         *      <li>C: Draw close.</li>
  7297.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7298.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7299.         *  </ul>
  7300.         * @param array $line_style Line style of ellipse. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7301.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  7302.         * @param integer $nc Number of curves used in ellipse. Default value: 8.
  7303.         * @access public
  7304.         * @since 2.1.000 (2008-01-08)
  7305.         */
  7306.         public function Ellipse($x0$y0$rx$ry=0$angle=0$astart=0$afinish=360$style=''$line_style=array()$fill_color=array()$nc=8{
  7307.             if ($angle{
  7308.                 $this->StartTransform();
  7309.                 $this->Rotate($angle$x0$y0);
  7310.                 $this->Ellipse($x0$y0$rx$ry0$astart$afinish$style$line_style$fill_color$nc);
  7311.                 $this->StopTransform();
  7312.                 return;
  7313.             }
  7314.             if ($rx{
  7315.                 if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7316.                     $this->SetFillColorArray($fill_color);
  7317.                 }
  7318.                 switch ($style{
  7319.                     case 'F'{
  7320.                         $op 'f';
  7321.                         $line_style array();
  7322.                         break;
  7323.                     }
  7324.                     case 'FD'
  7325.                     case 'DF'{
  7326.                         $op 'B';
  7327.                         break;
  7328.                     }
  7329.                     case 'C'{
  7330.                         $op 's'// Small 's' signifies closing the path as well
  7331.                         break;
  7332.                     }
  7333.                     case 'CNZ'{
  7334.                         $op 'W n';
  7335.                         break;
  7336.                     }
  7337.                     case 'CEO'{
  7338.                         $op 'W* n';
  7339.                         break;
  7340.                     }
  7341.                     default{
  7342.                         $op 'S';
  7343.                         break;
  7344.                     }
  7345.                 }
  7346.                 if ($line_style{
  7347.                     $this->SetLineStyle($line_style);
  7348.                 }
  7349.                 if (!$ry{
  7350.                     $ry $rx;
  7351.                 }
  7352.                 $rx *= $this->k;
  7353.                 $ry *= $this->k;
  7354.                 if ($nc 2{
  7355.                     $nc 2;
  7356.                 }
  7357.                 $astart deg2rad((float) $astart);
  7358.                 $afinish deg2rad((float) $afinish);
  7359.                 $total_angle $afinish $astart;
  7360.                 $dt $total_angle $nc;
  7361.                 $dtm $dt 3;
  7362.                 $x0 *= $this->k;
  7363.                 $y0 ($this->h - $y0$this->k;
  7364.                 $t1 $astart;
  7365.                 $a0 $x0 ($rx cos($t1));
  7366.                 $b0 $y0 ($ry sin($t1));
  7367.                 $c0 = -$rx sin($t1);
  7368.                 $d0 $ry cos($t1);
  7369.                 $this->_outPoint($a0 $this->k$this->h - ($b0 $this->k));
  7370.                 for ($i 1$i <= $nc++$i{
  7371.                     // Draw this bit of the total curve
  7372.                     $t1 ($i $dt$astart;
  7373.                     $a1 $x0 ($rx cos($t1));
  7374.                     $b1 $y0 ($ry sin($t1));
  7375.                     $c1 = -$rx sin($t1);
  7376.                     $d1 $ry cos($t1);
  7377.                     $this->_outCurve(($a0 ($c0 $dtm)) $this->k$this->h - (($b0 ($d0 $dtm)) $this->k)($a1 ($c1 $dtm)) $this->k$this->h - (($b1 ($d1 $dtm)) $this->k)$a1 $this->k$this->h - ($b1 $this->k));
  7378.                     $a0 $a1;
  7379.                     $b0 $b1;
  7380.                     $c0 $c1;
  7381.                     $d0 $d1;
  7382.                 }
  7383.                 $this->_out($op);
  7384.             }
  7385.         }
  7386.         
  7387.         /**
  7388.         * Draws a circle.
  7389.         * A circle is formed from n Bezier curves.
  7390.         * @param float $x0 Abscissa of center point.
  7391.         * @param float $y0 Ordinate of center point.
  7392.         * @param float $r Radius.
  7393.         * @param float $astart: Angle start of draw line. Default value: 0.
  7394.         * @param float $afinish: Angle finish of draw line. Default value: 360.
  7395.         * @param string $style Style of rendering. Possible values are:
  7396.         *  <ul>
  7397.         *      <li>D or empty string: Draw (default).</li>
  7398.         *      <li>F: Fill.</li>
  7399.         *      <li>DF or FD: Draw and fill.</li>
  7400.         *      <li>C: Draw close.</li>
  7401.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7402.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7403.         *  </ul>
  7404.         * @param array $line_style Line style of circle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7405.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  7406.         * @param integer $nc Number of curves used in circle. Default value: 8.
  7407.         * @access public
  7408.         * @since 2.1.000 (2008-01-08)
  7409.         */
  7410.         public function Circle($x0$y0$r$astart=0$afinish=360$style=''$line_style=array()$fill_color=array()$nc=8{
  7411.             $this->Ellipse($x0$y0$r00$astart$afinish$style$line_style$fill_color$nc);
  7412.         }
  7413.         
  7414.         /**
  7415.         * Draws a polygon.
  7416.         * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  7417.         * @param string $style Style of rendering. Possible values are:
  7418.         *  <ul>
  7419.         *      <li>D or empty string: Draw (default).</li>
  7420.         *      <li>F: Fill.</li>
  7421.         *      <li>DF or FD: Draw and fill.</li>
  7422.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7423.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7424.         *  </ul>
  7425.         * @param array $line_style Line style of polygon. Array with keys among the following:
  7426.         *  <ul>
  7427.         *      <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7428.         *      <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7429.         *  </ul>
  7430.         *  If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  7431.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  7432.         * @access public
  7433.         * @since 2.1.000 (2008-01-08)
  7434.         */
  7435.         public function Polygon($p$style=''$line_style=array()$fill_color=array()) {
  7436.             $np count($p2;
  7437.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7438.                 $this->SetFillColorArray($fill_color);
  7439.             }
  7440.             switch ($style{
  7441.                 case 'F'{
  7442.                     $line_style array();
  7443.                     $op 'f';
  7444.                     break;
  7445.                 }
  7446.                 case 'FD'
  7447.                 case 'DF'{
  7448.                     $op 'B';
  7449.                     break;
  7450.                 }
  7451.                 case 'CNZ'{
  7452.                     $op 'W n';
  7453.                     break;
  7454.                 }
  7455.                 case 'CEO'{
  7456.                     $op 'W* n';
  7457.                     break;
  7458.                 }                
  7459.                 default{
  7460.                     $op 'S';
  7461.                     break;
  7462.                 }
  7463.             }
  7464.             $draw true;
  7465.             if ($line_style{
  7466.                 if (isset($line_style['all'])) {
  7467.                     $this->SetLineStyle($line_style['all']);
  7468.                 else // 0 .. (np - 1), op = {B, S}
  7469.                     $draw false;
  7470.                     if ('B' == $op{
  7471.                         $op 'f';
  7472.                         $this->_outPoint($p[0]$p[1]);
  7473.                         for ($i 2$i ($np 2)$i $i 2{
  7474.                             $this->_outLine($p[$i]$p[$i 1]);
  7475.                         }
  7476.                         $this->_outLine($p[0]$p[1]);
  7477.                         $this->_out($op);
  7478.                     }
  7479.                     $p[($np 2)$p[0];
  7480.                     $p[(($np 21)$p[1];
  7481.                     for ($i 0$i $np++$i{
  7482.                         if (isset($line_style[$i]AND ($line_style[$i!= 0)) {
  7483.                             $this->Line($p[($i 2)]$p[(($i 21)]$p[(($i 22)]$p[(($i 23)]$line_style[$i]);
  7484.                         }
  7485.                     }
  7486.                 }
  7487.             }
  7488.             if ($draw{
  7489.                 $this->_outPoint($p[0]$p[1]);
  7490.                 for ($i 2$i ($np 2)$i $i 2{
  7491.                     $this->_outLine($p[$i]$p[$i 1]);
  7492.                 }
  7493.                 $this->_outLine($p[0]$p[1]);
  7494.                 $this->_out($op);
  7495.             }
  7496.         }
  7497.         
  7498.         /**
  7499.         * Draws a regular polygon.
  7500.         * @param float $x0 Abscissa of center point.
  7501.         * @param float $y0 Ordinate of center point.
  7502.         * @param float $r: Radius of inscribed circle.
  7503.         * @param integer $ns Number of sides.
  7504.         * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  7505.         * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  7506.         * @param string $style Style of rendering. Possible values are:
  7507.         *  <ul>
  7508.         *      <li>D or empty string: Draw (default).</li>
  7509.         *      <li>F: Fill.</li>
  7510.         *      <li>DF or FD: Draw and fill.</li>
  7511.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7512.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7513.         *  </ul>
  7514.         * @param array $line_style Line style of polygon sides. Array with keys among the following:
  7515.         *  <ul>
  7516.         *      <li>all: Line style of all sides. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7517.         *      <li>0 to ($ns - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7518.         *  </ul>
  7519.         *  If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  7520.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  7521.         * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  7522.         *  <ul>
  7523.         *      <li>D or empty string: Draw (default).</li>
  7524.         *      <li>F: Fill.</li>
  7525.         *      <li>DF or FD: Draw and fill.</li>
  7526.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7527.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7528.         *  </ul>
  7529.         * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7530.         * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  7531.         * @access public
  7532.         * @since 2.1.000 (2008-01-08)
  7533.         */
  7534.         public function RegularPolygon($x0$y0$r$ns$angle=0$draw_circle=false$style=''$line_style=array()$fill_color=array()$circle_style=''$circle_outLine_style=array()$circle_fill_color=array()) {
  7535.             if ($ns{
  7536.                 $ns 3;
  7537.             }
  7538.             if ($draw_circle{
  7539.                 $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  7540.             }
  7541.             $p array();
  7542.             for ($i 0$i $ns++$i{
  7543.                 $a $angle ($i 360 $ns);
  7544.                 $a_rad deg2rad((float) $a);
  7545.                 $p[$x0 ($r sin($a_rad));
  7546.                 $p[$y0 ($r cos($a_rad));
  7547.             }
  7548.             $this->Polygon($p$style$line_style$fill_color);
  7549.         }
  7550.         
  7551.         /**
  7552.         * Draws a star polygon
  7553.         * @param float $x0 Abscissa of center point.
  7554.         * @param float $y0 Ordinate of center point.
  7555.         * @param float $r Radius of inscribed circle.
  7556.         * @param integer $nv Number of vertices.
  7557.         * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  7558.         * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  7559.         * @param boolean $draw_circle: Draw inscribed circle or not. Default value is false.
  7560.         * @param string $style Style of rendering. Possible values are:
  7561.         *  <ul>
  7562.         *      <li>D or empty string: Draw (default).</li>
  7563.         *      <li>F: Fill.</li>
  7564.         *      <li>DF or FD: Draw and fill.</li>
  7565.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7566.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7567.         *  </ul>
  7568.         * @param array $line_style Line style of polygon sides. Array with keys among the following:
  7569.         *  <ul>
  7570.         *      <li>all: Line style of all sides. Array like for
  7571.         *  {@link SetLineStyle SetLineStyle}.</li>
  7572.         *      <li>0 to (n - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7573.         *  </ul>
  7574.         *  If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  7575.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  7576.         * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  7577.         *  <ul>
  7578.         *      <li>D or empty string: Draw (default).</li>
  7579.         *      <li>F: Fill.</li>
  7580.         *      <li>DF or FD: Draw and fill.</li>
  7581.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7582.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7583.         *  </ul>
  7584.         * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7585.         * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  7586.         * @access public
  7587.         * @since 2.1.000 (2008-01-08)
  7588.         */
  7589.         public function StarPolygon($x0$y0$r$nv$ng$angle=0$draw_circle=false$style=''$line_style=array()$fill_color=array()$circle_style=''$circle_outLine_style=array()$circle_fill_color=array()) {
  7590.             if ($nv{
  7591.                 $nv 2;
  7592.             }
  7593.             if ($draw_circle{
  7594.                 $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  7595.             }
  7596.             $p2 array();
  7597.             $visited array();
  7598.             for ($i 0$i $nv++$i{
  7599.                 $a $angle ($i 360 $nv);
  7600.                 $a_rad deg2rad((float) $a);
  7601.                 $p2[$x0 ($r sin($a_rad));
  7602.                 $p2[$y0 ($r cos($a_rad));
  7603.                 $visited[false;
  7604.             }
  7605.             $p array();
  7606.             $i 0;
  7607.             do {
  7608.                 $p[$p2[$i 2];
  7609.                 $p[$p2[($i 21];
  7610.                 $visited[$itrue;
  7611.                 $i += $ng;
  7612.                 $i %= $nv;
  7613.             while (!$visited[$i]);
  7614.             $this->Polygon($p$style$line_style$fill_color);
  7615.         }
  7616.         
  7617.         /**
  7618.         * Draws a rounded rectangle.
  7619.         * @param float $x Abscissa of upper-left corner.
  7620.         * @param float $y Ordinate of upper-left corner.
  7621.         * @param float $w Width.
  7622.         * @param float $h Height.
  7623.         * @param float $r Radius of the rounded corners.
  7624.         * @param string $round_corner Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
  7625.         * @param string $style Style of rendering. Possible values are:
  7626.         *  <ul>
  7627.         *      <li>D or empty string: Draw (default).</li>
  7628.         *      <li>F: Fill.</li>
  7629.         *      <li>DF or FD: Draw and fill.</li>
  7630.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7631.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7632.         *  </ul>
  7633.         * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7634.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  7635.         * @access public
  7636.         * @since 2.1.000 (2008-01-08)
  7637.         */
  7638.         public function RoundedRect($x$y$w$h$r$round_corner='1111'$style=''$border_style=array()$fill_color=array()) {
  7639.             if ('0000' == $round_corner// Not rounded
  7640.                 $this->Rect($x$y$w$h$style$border_style$fill_color);
  7641.             else // Rounded
  7642.                 if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7643.                     $this->SetFillColorArray($fill_color);
  7644.                 }
  7645.                 switch ($style{
  7646.                     case 'F'{
  7647.                         $border_style array();
  7648.                         $op 'f';
  7649.                         break;
  7650.                     }
  7651.                     case 'FD'
  7652.                     case 'DF'{
  7653.                         $op 'B';
  7654.                         break;
  7655.                     }
  7656.                     case 'CNZ'{
  7657.                         $op 'W n';
  7658.                         break;
  7659.                     }
  7660.                     case 'CEO'{
  7661.                         $op 'W* n';
  7662.                         break;
  7663.                     }
  7664.                     default{
  7665.                         $op 'S';
  7666.                         break;
  7667.                     }
  7668.                 }
  7669.                 if ($border_style{
  7670.                     $this->SetLineStyle($border_style);
  7671.                 }
  7672.                 $MyArc (sqrt(21);
  7673.                 $this->_outPoint($x $r$y);
  7674.                 $xc $x $w $r;
  7675.                 $yc $y $r;
  7676.                 $this->_outLine($xc$y);
  7677.                 if ($round_corner[0]{
  7678.                     $this->_outCurve($xc ($r $MyArc)$yc $r$xc $r$yc ($r $MyArc)$xc $r$yc);
  7679.                 else {
  7680.                     $this->_outLine($x $w$y);
  7681.                 }
  7682.                 $xc $x $w $r;
  7683.                 $yc $y $h $r;
  7684.                 $this->_outLine($x $w$yc);
  7685.                 if ($round_corner[1]{
  7686.                     $this->_outCurve($xc $r$yc ($r $MyArc)$xc ($r $MyArc)$yc $r$xc$yc $r);
  7687.                 else {
  7688.                     $this->_outLine($x $w$y $h);
  7689.                 }
  7690.                 $xc $x $r;
  7691.                 $yc $y $h $r;
  7692.                 $this->_outLine($xc$y $h);
  7693.                 if ($round_corner[2]{
  7694.                     $this->_outCurve($xc ($r $MyArc)$yc $r$xc $r$yc ($r $MyArc)$xc $r$yc);
  7695.                 else {
  7696.                     $this->_outLine($x$y $h);
  7697.                 }
  7698.                 $xc $x $r;
  7699.                 $yc $y $r;
  7700.                 $this->_outLine($x$yc);
  7701.                 if ($round_corner[3]{
  7702.                     $this->_outCurve($xc $r$yc ($r $MyArc)$xc ($r $MyArc)$yc $r$xc$yc $r);
  7703.                 else {
  7704.                     $this->_outLine($x$y);
  7705.                     $this->_outLine($x $r$y);
  7706.                 }
  7707.                 $this->_out($op);
  7708.             }
  7709.         }
  7710.         
  7711.         // END GRAPHIC FUNCTIONS SECTION -----------------------
  7712.         
  7713.         // BIDIRECTIONAL TEXT SECTION --------------------------
  7714.         /**
  7715.          * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  7716.          * @param string $str string to manipulate.
  7717.          * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  7718.          * @return string 
  7719.          * @author Nicola Asuni
  7720.          * @since 2.1.000 (2008-01-08)
  7721.         */
  7722.         protected function utf8StrRev($str$setbom=false$forcertl=false{
  7723.             return $this->arrUTF8ToUTF16BE($this->utf8Bidi($this->UTF8StringToArray($str)$forcertl)$setbom);
  7724.         }
  7725.         
  7726.         /**
  7727.          * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  7728.          * @param array $ta array of characters composing the string.
  7729.          * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  7730.          * @return string 
  7731.          * @author Nicola Asuni
  7732.          * @since 2.4.000 (2008-03-06)
  7733.         */
  7734.         protected function utf8Bidi($ta$forcertl=false{
  7735.             global $unicode$unicode_mirror$unicode_arlet$laa_array$diacritics;
  7736.             // paragraph embedding level
  7737.             $pel 0;
  7738.             // max level
  7739.             $maxlevel 0;
  7740.             // create string from array
  7741.             $str $this->UTF8ArrSubString($ta);
  7742.             // check if string contains arabic text
  7743.             if (preg_match(K_RE_PATTERN_ARABIC$str)) {
  7744.                 $arabic true;
  7745.             else {
  7746.                 $arabic false;
  7747.             }
  7748.             // check if string contains RTL text
  7749.             if (!($forcertl OR $arabic OR preg_match(K_RE_PATTERN_RTL$str))) {
  7750.                 return $ta;
  7751.             }
  7752.             
  7753.             // get number of chars
  7754.             $numchars count($ta);
  7755.             
  7756.             if ($forcertl == 'R'{
  7757.                     $pel 1;
  7758.             elseif ($forcertl == 'L'{
  7759.                     $pel 0;
  7760.             else {
  7761.                 // P2. In each paragraph, find the first character of type L, AL, or R.
  7762.                 // P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
  7763.                 for ($i=0$i $numchars++$i{
  7764.                     $type $unicode[$ta[$i]];
  7765.                     if ($type == 'L'{
  7766.                         $pel 0;
  7767.                         break;
  7768.                     elseif (($type == 'AL'OR ($type == 'R')) {
  7769.                         $pel 1;
  7770.                         break;
  7771.                     }
  7772.                 }
  7773.             }
  7774.             
  7775.             // Current Embedding Level
  7776.             $cel $pel;
  7777.             // directional override status
  7778.             $dos 'N';
  7779.             $remember array();
  7780.             // start-of-level-run
  7781.             $sor $pel 'R' 'L';
  7782.             $eor $sor;
  7783.             
  7784.             // Array of characters data
  7785.             $chardata Array();
  7786.             
  7787.             // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
  7788.             //     In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  7789.             for ($i=0$i $numchars++$i{
  7790.                 if ($ta[$i== K_RLE{
  7791.                     // X2. With each RLE, compute the least greater odd embedding level.
  7792.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  7793.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  7794.                     $next_level $cel ($cel 21;
  7795.                     if ($next_level 62{
  7796.                         $remember[array('num' => K_RLE'cel' => $cel'dos' => $dos);
  7797.                         $cel $next_level;
  7798.                         $dos 'N';
  7799.                         $sor $eor;
  7800.                         $eor $cel 'R' 'L';
  7801.                     }
  7802.                 elseif ($ta[$i== K_LRE{
  7803.                     // X3. With each LRE, compute the least greater even embedding level.
  7804.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  7805.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  7806.                     $next_level $cel ($cel 2);
  7807.                     if $next_level 62 {
  7808.                         $remember[array('num' => K_LRE'cel' => $cel'dos' => $dos);
  7809.                         $cel $next_level;
  7810.                         $dos 'N';
  7811.                         $sor $eor;
  7812.                         $eor $cel 'R' 'L';
  7813.                     }
  7814.                 elseif ($ta[$i== K_RLO{
  7815.                     // X4. With each RLO, compute the least greater odd embedding level.
  7816.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
  7817.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  7818.                     $next_level $cel ($cel 21;
  7819.                     if ($next_level 62{
  7820.                         $remember[array('num' => K_RLO'cel' => $cel'dos' => $dos);
  7821.                         $cel $next_level;
  7822.                         $dos 'R';
  7823.                         $sor $eor;
  7824.                         $eor $cel 'R' 'L';
  7825.                     }
  7826.                 elseif ($ta[$i== K_LRO{
  7827.                     // X5. With each LRO, compute the least greater even embedding level.
  7828.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
  7829.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  7830.                     $next_level $cel ($cel 2);
  7831.                     if $next_level 62 {
  7832.                         $remember[array('num' => K_LRO'cel' => $cel'dos' => $dos);
  7833.                         $cel $next_level;
  7834.                         $dos 'L';
  7835.                         $sor $eor;
  7836.                         $eor $cel 'R' 'L';
  7837.                     }
  7838.                 elseif ($ta[$i== K_PDF{
  7839.                     // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
  7840.                     if (count($remember)) {
  7841.                         $last count($remember 1;
  7842.                         if (($remember[$last]['num'== K_RLEOR 
  7843.                               ($remember[$last]['num'== K_LREOR 
  7844.                               ($remember[$last]['num'== K_RLOOR 
  7845.                               ($remember[$last]['num'== K_LRO)) {
  7846.                             $match array_pop($remember);
  7847.                             $cel $match['cel'];
  7848.                             $dos $match['dos'];
  7849.                             $sor $eor;
  7850.                             $eor ($cel $match['cel'$cel $match['cel']'R' 'L';
  7851.                         }
  7852.                     }
  7853.                 elseif (($ta[$i!= K_RLEAND
  7854.                                  ($ta[$i!= K_LREAND
  7855.                                  ($ta[$i!= K_RLOAND
  7856.                                  ($ta[$i!= K_LROAND
  7857.                                  ($ta[$i!= K_PDF)) {
  7858.                     // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  7859.                     //    a. Set the level of the current character to the current embedding level.
  7860.                     //    b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  7861.                     if ($dos != 'N'{
  7862.                         $chardir $dos;
  7863.                     else {
  7864.                         $chardir $unicode[$ta[$i]];
  7865.                     }
  7866.                     // stores string characters and other information
  7867.                     $chardata[array('char' => $ta[$i]'level' => $cel'type' => $chardir'sor' => $sor'eor' => $eor);
  7868.                 }
  7869.             // end for each char
  7870.             
  7871.             // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  7872.             // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  7873.             // X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L.
  7874.             
  7875.             // 3.3.3 Resolving Weak Types
  7876.             // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
  7877.             // Nonspacing marks are now resolved based on the previous characters.
  7878.             $numchars count($chardata);
  7879.             
  7880.             // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
  7881.             $prevlevel = -1// track level changes
  7882.             $levcount 0// counts consecutive chars at the same level
  7883.             for ($i=0$i $numchars++$i{
  7884.                 if ($chardata[$i]['type'== 'NSM'{
  7885.                     if ($levcount{
  7886.                         $chardata[$i]['type'$chardata[$i]['sor'];
  7887.                     elseif ($i 0{
  7888.                         $chardata[$i]['type'$chardata[($i-1)]['type'];
  7889.                     }
  7890.                 }
  7891.                 if ($chardata[$i]['level'!= $prevlevel{
  7892.                     $levcount 0;
  7893.                 else {
  7894.                     ++$levcount;
  7895.                 }
  7896.                 $prevlevel $chardata[$i]['level'];
  7897.             }
  7898.             
  7899.             // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
  7900.             $prevlevel = -1;
  7901.             $levcount 0;
  7902.             for ($i=0$i $numchars++$i{
  7903.                 if ($chardata[$i]['char'== 'EN'{
  7904.                     for ($j=$levcount$j >= 0$j--{
  7905.                         if ($chardata[$j]['type'== 'AL'{
  7906.                             $chardata[$i]['type''AN';
  7907.                         elseif (($chardata[$j]['type'== 'L'OR ($chardata[$j]['type'== 'R')) {
  7908.                             break;
  7909.                         }
  7910.                     }
  7911.                 }
  7912.                 if ($chardata[$i]['level'!= $prevlevel{
  7913.                     $levcount 0;
  7914.                 else {
  7915.                     ++$levcount;
  7916.                 }
  7917.                 $prevlevel $chardata[$i]['level'];
  7918.             }
  7919.             
  7920.             // W3. Change all ALs to R.
  7921.             for ($i=0$i $numchars++$i{
  7922.                 if ($chardata[$i]['type'== 'AL'{
  7923.                     $chardata[$i]['type''R';
  7924.                 
  7925.             }
  7926.             
  7927.             // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
  7928.             $prevlevel = -1;
  7929.             $levcount 0;
  7930.             for ($i=0$i $numchars++$i{
  7931.                 if (($levcount 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  7932.                     if (($chardata[$i]['type'== 'ES'AND ($chardata[($i-1)]['type'== 'EN'AND ($chardata[($i+1)]['type'== 'EN')) {
  7933.                         $chardata[$i]['type''EN';
  7934.                     elseif (($chardata[$i]['type'== 'CS'AND ($chardata[($i-1)]['type'== 'EN'AND ($chardata[($i+1)]['type'== 'EN')) {
  7935.                         $chardata[$i]['type''EN';
  7936.                     elseif (($chardata[$i]['type'== 'CS'AND ($chardata[($i-1)]['type'== 'AN'AND ($chardata[($i+1)]['type'== 'AN')) {
  7937.                         $chardata[$i]['type''AN';
  7938.                     }
  7939.                 }
  7940.                 if ($chardata[$i]['level'!= $prevlevel{
  7941.                     $levcount 0;
  7942.                 else {
  7943.                     ++$levcount;
  7944.                 }
  7945.                 $prevlevel $chardata[$i]['level'];
  7946.             }
  7947.             
  7948.             // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  7949.             $prevlevel = -1;
  7950.             $levcount 0;
  7951.             for ($i=0$i $numchars++$i{
  7952.                 if ($chardata[$i]['type'== 'ET'{
  7953.                     if (($levcount 0AND ($chardata[($i-1)]['type'== 'EN')) {
  7954.                         $chardata[$i]['type''EN';
  7955.                     else {
  7956.                         $j $i+1;
  7957.                         while (($j $numcharsAND ($chardata[$j]['level'== $prevlevel)) {
  7958.                             if ($chardata[$j]['type'== 'EN'{
  7959.                                 $chardata[$i]['type''EN';
  7960.                                 break;
  7961.                             elseif ($chardata[$j]['type'!= 'ET'{
  7962.                                 break;
  7963.                             }
  7964.                             ++$j;
  7965.                         }
  7966.                     }
  7967.                 }
  7968.                 if ($chardata[$i]['level'!= $prevlevel{
  7969.                     $levcount 0;
  7970.                 else {
  7971.                     ++$levcount;
  7972.                 }
  7973.                 $prevlevel $chardata[$i]['level'];
  7974.             }
  7975.             
  7976.             // W6. Otherwise, separators and terminators change to Other Neutral.
  7977.             $prevlevel = -1;
  7978.             $levcount 0;
  7979.             for ($i=0$i $numchars++$i{
  7980.                 if (($chardata[$i]['type'== 'ET'OR ($chardata[$i]['type'== 'ES'OR ($chardata[$i]['type'== 'CS')) {
  7981.                     $chardata[$i]['type''ON';
  7982.                 }
  7983.                 if ($chardata[$i]['level'!= $prevlevel{
  7984.                     $levcount 0;
  7985.                 else {
  7986.                     ++$levcount;
  7987.                 }
  7988.                 $prevlevel $chardata[$i]['level'];
  7989.             }
  7990.             
  7991.             //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
  7992.             $prevlevel = -1;
  7993.             $levcount 0;
  7994.             for ($i=0$i $numchars++$i{
  7995.                 if ($chardata[$i]['char'== 'EN'{
  7996.                     for ($j=$levcount$j >= 0$j--{
  7997.                         if ($chardata[$j]['type'== 'L'{
  7998.                             $chardata[$i]['type''L';
  7999.                         elseif ($chardata[$j]['type'== 'R'{
  8000.                             break;
  8001.                         }
  8002.                     }
  8003.                 }
  8004.                 if ($chardata[$i]['level'!= $prevlevel{
  8005.                     $levcount 0;
  8006.                 else {
  8007.                     ++$levcount;
  8008.                 }
  8009.                 $prevlevel $chardata[$i]['level'];
  8010.             }
  8011.             
  8012.             // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
  8013.             $prevlevel = -1;
  8014.             $levcount 0;
  8015.             for ($i=0$i $numchars++$i{
  8016.                 if (($levcount 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  8017.                     if (($chardata[$i]['type'== 'N'AND ($chardata[($i-1)]['type'== 'L'AND ($chardata[($i+1)]['type'== 'L')) {
  8018.                         $chardata[$i]['type''L';
  8019.                     elseif (($chardata[$i]['type'== 'N'AND
  8020.                      (($chardata[($i-1)]['type'== 'R'OR ($chardata[($i-1)]['type'== 'EN'OR ($chardata[($i-1)]['type'== 'AN')) AND
  8021.                      (($chardata[($i+1)]['type'== 'R'OR ($chardata[($i+1)]['type'== 'EN'OR ($chardata[($i+1)]['type'== 'AN'))) {
  8022.                         $chardata[$i]['type''R';
  8023.                     elseif ($chardata[$i]['type'== 'N'{
  8024.                         // N2. Any remaining neutrals take the embedding direction
  8025.                         $chardata[$i]['type'$chardata[$i]['sor'];
  8026.                     }
  8027.                 elseif (($levcount == 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  8028.                     // first char
  8029.                     if (($chardata[$i]['type'== 'N'AND ($chardata[$i]['sor'== 'L'AND ($chardata[($i+1)]['type'== 'L')) {
  8030.                         $chardata[$i]['type''L';
  8031.                     elseif (($chardata[$i]['type'== 'N'AND
  8032.                      (($chardata[$i]['sor'== 'R'OR ($chardata[$i]['sor'== 'EN'OR ($chardata[$i]['sor'== 'AN')) AND
  8033.                      (($chardata[($i+1)]['type'== 'R'OR ($chardata[($i+1)]['type'== 'EN'OR ($chardata[($i+1)]['type'== 'AN'))) {
  8034.                         $chardata[$i]['type''R';
  8035.                     elseif ($chardata[$i]['type'== 'N'{
  8036.                         // N2. Any remaining neutrals take the embedding direction
  8037.                         $chardata[$i]['type'$chardata[$i]['sor'];
  8038.                     }
  8039.                 elseif (($levcount 0AND ((($i+1== $numcharsOR (($i+1$numcharsAND ($chardata[($i+1)]['level'!= $prevlevel))) {
  8040.                     //last char
  8041.                     if (($chardata[$i]['type'== 'N'AND ($chardata[($i-1)]['type'== 'L'AND ($chardata[$i]['eor'== 'L')) {
  8042.                         $chardata[$i]['type''L';
  8043.                     elseif (($chardata[$i]['type'== 'N'AND
  8044.                      (($chardata[($i-1)]['type'== 'R'OR ($chardata[($i-1)]['type'== 'EN'OR ($chardata[($i-1)]['type'== 'AN')) AND
  8045.                      (($chardata[$i]['eor'== 'R'OR ($chardata[$i]['eor'== 'EN'OR ($chardata[$i]['eor'== 'AN'))) {
  8046.                         $chardata[$i]['type''R';
  8047.                     elseif ($chardata[$i]['type'== 'N'{
  8048.                         // N2. Any remaining neutrals take the embedding direction
  8049.                         $chardata[$i]['type'$chardata[$i]['sor'];
  8050.                     }
  8051.                 elseif ($chardata[$i]['type'== 'N'{
  8052.                     // N2. Any remaining neutrals take the embedding direction
  8053.                     $chardata[$i]['type'$chardata[$i]['sor'];
  8054.                 }
  8055.                 if ($chardata[$i]['level'!= $prevlevel{
  8056.                     $levcount 0;
  8057.                 else {
  8058.                     ++$levcount;
  8059.                 }
  8060.                 $prevlevel $chardata[$i]['level'];
  8061.             }
  8062.             
  8063.             // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
  8064.             // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  8065.             for ($i=0$i $numchars++$i{
  8066.                 $odd $chardata[$i]['level'2;
  8067.                 if ($odd{
  8068.                     if (($chardata[$i]['type'== 'L'OR ($chardata[$i]['type'== 'AN'OR ($chardata[$i]['type'== 'EN')) {
  8069.                         $chardata[$i]['level'+= 1;
  8070.                     }
  8071.                 else {
  8072.                     if ($chardata[$i]['type'== 'R'{
  8073.                         $chardata[$i]['level'+= 1;
  8074.                     elseif (($chardata[$i]['type'== 'AN'OR ($chardata[$i]['type'== 'EN')) {
  8075.                         $chardata[$i]['level'+= 2;
  8076.                     }
  8077.                 }
  8078.                 $maxlevel max($chardata[$i]['level'],$maxlevel);
  8079.             }
  8080.             
  8081.             // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  8082.             //    1. Segment separators,
  8083.             //    2. Paragraph separators,
  8084.             //    3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  8085.             //    4. Any sequence of white space characters at the end of the line.
  8086.             for ($i=0$i $numchars++$i{
  8087.                 if (($chardata[$i]['type'== 'B'OR ($chardata[$i]['type'== 'S')) {
  8088.                     $chardata[$i]['level'$pel;
  8089.                 elseif ($chardata[$i]['type'== 'WS'{
  8090.                     $j $i+1;
  8091.                     while ($j $numchars{
  8092.                         if ((($chardata[$j]['type'== 'B'OR ($chardata[$j]['type'== 'S')) OR
  8093.                             (($j == ($numchars-1)) AND ($chardata[$j]['type'== 'WS'))) {
  8094.                             $chardata[$i]['level'$pel;
  8095.                             break;
  8096.                         elseif ($chardata[$j]['type'!= 'WS'{
  8097.                             break;
  8098.                         }
  8099.                         ++$j;
  8100.                     }
  8101.                 }
  8102.             }
  8103.             
  8104.             // Arabic Shaping
  8105.             // Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run. 
  8106.             if ($arabic{
  8107.                 $endedletter array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
  8108.                 $alfletter array(1570,1571,1573,1575);
  8109.                 $chardata2 $chardata;
  8110.                 $laaletter false;
  8111.                 $charAL array();
  8112.                 $x 0;
  8113.                 for ($i=0$i $numchars++$i{
  8114.                     if (($unicode[$chardata[$i]['char']] == 'AL'OR ($chardata[$i]['char'== 32OR ($chardata[$i]['char'== 8204)) {
  8115.                         $charAL[$x$chardata[$i];
  8116.                         $charAL[$x]['i'$i;
  8117.                         $chardata[$i]['x'$x;
  8118.                         ++$x;
  8119.                     }
  8120.                 }
  8121.                 $numAL $x;
  8122.                 for ($i=0$i $numchars++$i{
  8123.                     $thischar $chardata[$i];
  8124.                     if ($i 0{
  8125.                         $prevchar $chardata[($i-1)];
  8126.                     else {
  8127.                         $prevchar false;
  8128.                     }
  8129.                     if (($i+1$numchars{
  8130.                         $nextchar $chardata[($i+1)];
  8131.                     else {
  8132.                         $nextchar false;
  8133.                     }
  8134.                     if ($unicode[$thischar['char']] == 'AL'{
  8135.                         $x $thischar['x'];
  8136.                         if ($x 0{
  8137.                             $prevchar $charAL[($x-1)];
  8138.                         else {
  8139.                             $prevchar false;
  8140.                         }
  8141.                         if (($x+1$numAL{
  8142.                             $nextchar $charAL[($x+1)];
  8143.                         else {
  8144.                             $nextchar false;
  8145.                         }
  8146.                         // if laa letter
  8147.                         if (($prevchar !== falseAND ($prevchar['char'== 1604AND (in_array($thischar['char']$alfletter))) {
  8148.                             $arabicarr $laa_array;
  8149.                             $laaletter true;
  8150.                             if ($x 1{
  8151.                                 $prevchar $charAL[($x-2)];
  8152.                             else {
  8153.                                 $prevchar false;
  8154.                             }
  8155.                         else {
  8156.                             $arabicarr $unicode_arlet;
  8157.                             $laaletter false;
  8158.                         }
  8159.                         if (($prevchar !== falseAND ($nextchar !== falseAND
  8160.                             (($unicode[$prevchar['char']] == 'AL'OR ($unicode[$prevchar['char']] == 'NSM')) AND
  8161.                             (($unicode[$nextchar['char']] == 'AL'OR ($unicode[$nextchar['char']] == 'NSM')) AND
  8162.                             ($prevchar['type'== $thischar['type']AND
  8163.                             ($nextchar['type'== $thischar['type']AND
  8164.                             ($nextchar['char'!= 1567)) {
  8165.                             if (in_array($prevchar['char']$endedletter)) {
  8166.                                 if (isset($arabicarr[$thischar['char']][2])) {
  8167.                                     // initial
  8168.                                     $chardata2[$i]['char'$arabicarr[$thischar['char']][2];
  8169.                                 }
  8170.                             else {
  8171.                                 if (isset($arabicarr[$thischar['char']][3])) {
  8172.                                     // medial
  8173.                                     $chardata2[$i]['char'$arabicarr[$thischar['char']][3];
  8174.                                 }
  8175.                             }
  8176.                         elseif (($nextchar !== falseAND
  8177.                             (($unicode[$nextchar['char']] == 'AL'OR ($unicode[$nextchar['char']] == 'NSM')) AND
  8178.                             ($nextchar['type'== $thischar['type']AND
  8179.                             ($nextchar['char'!= 1567)) {
  8180.                             if (isset($arabicarr[$chardata[$i]['char']][2])) {
  8181.                                 // initial
  8182.                                 $chardata2[$i]['char'$arabicarr[$thischar['char']][2];
  8183.                             }
  8184.                         elseif ((($prevchar !== falseAND
  8185.                             (($unicode[$prevchar['char']] == 'AL'OR ($unicode[$prevchar['char']] == 'NSM')) AND
  8186.                             ($prevchar['type'== $thischar['type'])) OR
  8187.                             (($nextchar !== falseAND ($nextchar['char'== 1567))) {
  8188.                             // final
  8189.                             if (($i 1AND ($thischar['char'== 1607AND
  8190.                                 ($chardata[$i-1]['char'== 1604AND
  8191.                                 ($chardata[$i-2]['char'== 1604)) {
  8192.                                 //Allah Word
  8193.                                 // mark characters to delete with false
  8194.                                 $chardata2[$i-2]['char'false;
  8195.                                 $chardata2[$i-1]['char'false
  8196.                                 $chardata2[$i]['char'65010;
  8197.                             else {
  8198.                                 if (($prevchar !== falseAND in_array($prevchar['char']$endedletter)) {
  8199.                                     if (isset($arabicarr[$thischar['char']][0])) {
  8200.                                         // isolated
  8201.                                         $chardata2[$i]['char'$arabicarr[$thischar['char']][0];
  8202.                                     }
  8203.                                 else {
  8204.                                     if (isset($arabicarr[$thischar['char']][1])) {
  8205.                                         // final
  8206.                                         $chardata2[$i]['char'$arabicarr[$thischar['char']][1];
  8207.                                     }
  8208.                                 }
  8209.                             }
  8210.                         elseif (isset($arabicarr[$thischar['char']][0])) {
  8211.                             // isolated
  8212.                             $chardata2[$i]['char'$arabicarr[$thischar['char']][0];
  8213.                         }
  8214.                         // if laa letter
  8215.                         if ($laaletter{
  8216.                             // mark characters to delete with false
  8217.                             $chardata2[($charAL[($x-1)]['i'])]['char'false;
  8218.                         }
  8219.                     // end if AL (Arabic Letter)
  8220.                 // end for each char
  8221.                 /* 
  8222.                  * Combining characters that can occur with Shadda (0651 HEX, 1617 DEC) are placed in UE586-UE594. 
  8223.                  * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  8224.                  */
  8225.                 $cw &$this->CurrentFont['cw'];
  8226.                 for ($i 0$i ($numchars-1)++$i{
  8227.                     if (($chardata2[$i]['char'== 1617AND (isset($diacritics[($chardata2[$i+1]['char'])]))) {
  8228.                         // check if the subtitution font is defined on current font
  8229.                         if (isset($cw[($diacritics[($chardata2[$i+1]['char'])])])) {
  8230.                             $chardata2[$i]['char'false;
  8231.                             $chardata2[$i+1]['char'$diacritics[($chardata2[$i+1]['char'])];
  8232.                         }
  8233.                     }
  8234.                 }
  8235.                 // remove marked characters
  8236.                 foreach ($chardata2 as $key => $value{
  8237.                     if ($value['char'=== false{
  8238.                         unset($chardata2[$key]);
  8239.                     }
  8240.                 }
  8241.                 $chardata array_values($chardata2);
  8242.                 $numchars count($chardata);
  8243.                 unset($chardata2);
  8244.                 unset($arabicarr);
  8245.                 unset($laaletter);
  8246.                 unset($charAL);
  8247.             }
  8248.             
  8249.             // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
  8250.             for ($j=$maxlevel$j 0$j--{
  8251.                 $ordarray Array();
  8252.                 $revarr Array();
  8253.                 $onlevel false;
  8254.                 for ($i=0$i $numchars++$i{
  8255.                     if ($chardata[$i]['level'>= $j{
  8256.                         $onlevel true;
  8257.                         if (isset($unicode_mirror[$chardata[$i]['char']])) {
  8258.                             // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
  8259.                             $chardata[$i]['char'$unicode_mirror[$chardata[$i]['char']];
  8260.                         }
  8261.                         $revarr[$chardata[$i];
  8262.                     else {
  8263.                         if ($onlevel{
  8264.                             $revarr array_reverse($revarr);
  8265.                             $ordarray array_merge($ordarray$revarr);
  8266.                             $revarr Array();
  8267.                             $onlevel false;
  8268.                         }
  8269.                         $ordarray[$chardata[$i];
  8270.                     }
  8271.                 }
  8272.                 if ($onlevel{
  8273.                     $revarr array_reverse($revarr);
  8274.                     $ordarray array_merge($ordarray$revarr);
  8275.                 }
  8276.                 $chardata $ordarray;
  8277.             }
  8278.             
  8279.             $ordarray array();
  8280.             for ($i=0$i $numchars++$i{
  8281.                 $ordarray[$chardata[$i]['char'];
  8282.             }
  8283.             
  8284.             return $ordarray;
  8285.         }
  8286.         
  8287.         // END OF BIDIRECTIONAL TEXT SECTION -------------------
  8288.         
  8289.         /*
  8290.         * Adds a bookmark.
  8291.         * @param string $txt bookmark description.
  8292.         * @param int $level bookmark level (minimum value is 0).
  8293.         * @param float $y Ordinate of the boorkmark position (default = -1 = current position).
  8294.         * @param int $page target page number (leave empty for current page).
  8295.         * @access public
  8296.         * @author Olivier Plathey, Nicola Asuni
  8297.         * @since 2.1.002 (2008-02-12)
  8298.         */
  8299.         public function Bookmark($txt$level=0$y=-1$page=''{
  8300.             if ($level 0{
  8301.                 $level 0;
  8302.             }
  8303.             if (isset($this->outlines[0])) {
  8304.                 $lastoutline end($this->outlines);
  8305.                 $maxlevel $lastoutline['l'1;
  8306.             else {
  8307.                 $maxlevel 0;
  8308.             }
  8309.             if ($level $maxlevel{
  8310.                 $level $maxlevel;
  8311.             }
  8312.             if ($y == -1{
  8313.                 $y $this->GetY();
  8314.             }
  8315.             if (empty($page)) {
  8316.                 $page $this->PageNo();
  8317.             }
  8318.             $this->outlines[array('t' => $txt'l' => $level'y' => $y'p' => $page);
  8319.         }
  8320.         
  8321.         /*
  8322.         * Create a bookmark PDF string.
  8323.         * @access protected
  8324.         * @author Olivier Plathey, Nicola Asuni
  8325.         * @since 2.1.002 (2008-02-12)
  8326.         */
  8327.         protected function _putbookmarks({
  8328.             $nb count($this->outlines);
  8329.             if ($nb == 0{
  8330.                 return;
  8331.             }
  8332.             $lru array();
  8333.             $level 0;
  8334.             foreach ($this->outlines as $i => $o{
  8335.                 if ($o['l'0{
  8336.                     $parent $lru[($o['l'1)];
  8337.                     //Set parent and last pointers
  8338.                     $this->outlines[$i]['parent'$parent;
  8339.                     $this->outlines[$parent]['last'$i;
  8340.                     if ($o['l'$level{
  8341.                         //Level increasing: set first pointer
  8342.                         $this->outlines[$parent]['first'$i;
  8343.                     }
  8344.                 else {
  8345.                     $this->outlines[$i]['parent'$nb;
  8346.                 }
  8347.                 if (($o['l'<= $levelAND ($i 0)) {
  8348.                     //Set prev and next pointers
  8349.                     $prev $lru[$o['l']];
  8350.                     $this->outlines[$prev]['next'$i;
  8351.                     $this->outlines[$i]['prev'$prev;
  8352.                 }
  8353.                 $lru[$o['l']] $i;
  8354.                 $level $o['l'];
  8355.             }
  8356.             //Outline items
  8357.             $n $this->n + 1;
  8358.             foreach ($this->outlines as $i => $o{
  8359.                 $this->_newobj();
  8360.                 $this->_out('<</Title '.$this->_textstring($o['t']));
  8361.                 $this->_out('/Parent '.($n $o['parent']).' 0 R');
  8362.                 if (isset($o['prev']))
  8363.                 $this->_out('/Prev '.($n $o['prev']).' 0 R');
  8364.                 if (isset($o['next']))
  8365.                 $this->_out('/Next '.($n $o['next']).' 0 R');
  8366.                 if (isset($o['first']))
  8367.                 $this->_out('/First '.($n $o['first']).' 0 R');
  8368.                 if (isset($o['last']))
  8369.                 $this->_out('/Last '.($n $o['last']).' 0 R');
  8370.                 $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]'(($o['p']))($this->pagedim[$o['p']]['h'($o['y'$this->k))));
  8371.                 $this->_out('/Count 0>>');
  8372.                 $this->_out('endobj');
  8373.             }
  8374.             //Outline root
  8375.             $this->_newobj();
  8376.             $this->OutlineRoot = $this->n;
  8377.             $this->_out('<</Type /Outlines /First '.$n.' 0 R');
  8378.             $this->_out('/Last '.($n $lru[0]).' 0 R>>');
  8379.             $this->_out('endobj');
  8380.         }
  8381.         
  8382.         
  8383.         // --- JAVASCRIPT - FORMS ------------------------------
  8384.         
  8385.         /*
  8386.         * Adds a javascript
  8387.         * @access public
  8388.         * @author Johannes Güntert, Nicola Asuni
  8389.         * @since 2.1.002 (2008-02-12)
  8390.         */
  8391.         public function IncludeJS($script{
  8392.             $this->javascript .= $script;
  8393.         }
  8394.         
  8395.         /*
  8396.         * Create a javascript PDF string.
  8397.         * @access protected
  8398.         * @author Johannes Güntert, Nicola Asuni
  8399.         * @since 2.1.002 (2008-02-12)
  8400.         */
  8401.         protected function _putjavascript({
  8402.             if (empty($this->javascript)) {
  8403.                 return;
  8404.             }
  8405.             // the following two lines are uded to avoid form fields duplication after saving
  8406.             $js1 sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2f,%.2f,%.2f,%.2f]);"'tcpdfdocsaved''text'00101);
  8407.             $js2 "getField('tcpdfdocsaved').value = 'saved';";
  8408.             $this->_newobj();
  8409.             $this->n_js = $this->n;
  8410.             $this->_out('<<');
  8411.             $this->_out('/Names [(EmbeddedJS) '.($this->n + 1).' 0 R ]');
  8412.             $this->_out('>>');
  8413.             $this->_out('endobj');
  8414.             $this->_newobj();
  8415.             $this->_out('<<');
  8416.             $this->_out('/S /JavaScript');
  8417.             $this->_out('/JS '.$this->_textstring($js1."\n".$this->javascript."\n".$js2));
  8418.             $this->_out('>>');
  8419.             $this->_out('endobj');
  8420.         }
  8421.         
  8422.         /*
  8423.         * Convert color to javascript color.
  8424.         * @param string $color color name or #RRGGBB
  8425.         * @access protected
  8426.         * @author Denis Van Nuffelen, Nicola Asuni
  8427.         * @since 2.1.002 (2008-02-12)
  8428.         */
  8429.         protected function _JScolor($color{
  8430.             static $aColors array('transparent''black''white''red''green''blue''cyan''magenta''yellow''dkGray''gray''ltGray');
  8431.             if (substr($color,0,1== '#'{
  8432.                 return sprintf("['RGB',%.3f,%.3f,%.3f]"hexdec(substr($color,1,2))/255hexdec(substr($color,3,2))/255hexdec(substr($color,5,2))/255);
  8433.             }
  8434.             if (!in_array($color,$aColors)) {
  8435.                 $this->Error('Invalid color: '.$color);
  8436.             }
  8437.             return 'color.'.$color;
  8438.         }
  8439.         
  8440.         /*
  8441.         * Adds a javascript form field.
  8442.         * @param string $type field type
  8443.         * @param string $name field name
  8444.         * @param int $x horizontal position
  8445.         * @param int $y vertical position
  8446.         * @param int $w width
  8447.         * @param int $h height
  8448.         * @param array $prop array of properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8449.         * @access protected
  8450.         * @author Denis Van Nuffelen, Nicola Asuni
  8451.         * @since 2.1.002 (2008-02-12)
  8452.         */
  8453.         protected function _addfield($type$name$x$y$w$h$prop{
  8454.             if ($this->rtl{
  8455.                 $x $x $w;
  8456.             }
  8457.             // the followind avoid fields duplication after saving the document
  8458.             $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {";
  8459.             $k $this->k;
  8460.             $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%d,[%.2f,%.2f,%.2f,%.2f]);"$name$type$this->PageNo()-1$x*$k($this->h-$y)*$k+1($x+$w)*$k($this->h-$y-$h)*$k+1)."\n";
  8461.             $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  8462.             while (list($key$valeach($prop)) {
  8463.                 if (strcmp(substr($key-5)'Color'== 0{
  8464.                     $val $this->_JScolor($val);
  8465.                 else {
  8466.                     $val "'".$val."'";
  8467.                 }
  8468.                 $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  8469.             }
  8470.             if ($this->rtl{
  8471.                 $this->x -= $w;
  8472.             else {
  8473.                 $this->x += $w;
  8474.             }
  8475.             $this->javascript .= '}';
  8476.         }
  8477.         
  8478.         /*
  8479.         * Creates a text field
  8480.         * @param string $name field name
  8481.         * @param int $w width
  8482.         * @param int $h height
  8483.         * @param string $prop properties. The value property allows to set the initial value. The multiline property allows to define the field as multiline. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8484.         * @access public
  8485.         * @author Denis Van Nuffelen, Nicola Asuni
  8486.         * @since 2.1.002 (2008-02-12)
  8487.         */
  8488.         public function TextField($name$w$h$prop=array()) {
  8489.             $this->_addfield('text'$name$this->x$this->y$w$h$prop);
  8490.         }
  8491.         
  8492.         /*
  8493.         * Creates a RadioButton field
  8494.         * @param string $name field name
  8495.         * @param int $w width
  8496.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8497.         * @access public
  8498.         * @author Nicola Asuni
  8499.         * @since 2.2.003 (2008-03-03)
  8500.         */
  8501.         public function RadioButton($name$w$prop=array()) {
  8502.             if (!isset($prop['strokeColor'])) {
  8503.                 $prop['strokeColor']='black';
  8504.             }
  8505.             $this->_addfield('radiobutton'$name$this->x$this->y$w$w$prop);
  8506.         }
  8507.         
  8508.         /*
  8509.         * Creates a List-box field
  8510.         * @param string $name field name
  8511.         * @param int $w width
  8512.         * @param int $h height
  8513.         * @param array $values array containing the list of values.
  8514.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8515.         * @access public
  8516.         * @author Nicola Asuni
  8517.         * @since 2.2.003 (2008-03-03)
  8518.         */
  8519.         public function ListBox($name$w$h$values$prop=array()) {
  8520.             if (!isset($prop['strokeColor'])) {
  8521.                 $prop['strokeColor''ltGray';
  8522.             }
  8523.             $this->_addfield('listbox'$name$this->x$this->y$w$h$prop);
  8524.             $s '';
  8525.             foreach ($values as $value{
  8526.                 $s .= "'".addslashes($value)."',";
  8527.             }
  8528.             $this->javascript .= 'f'.$name.'.setItems(['.substr($s0-1)."]);\n";
  8529.         }
  8530.         
  8531.         /*
  8532.         * Creates a Combo-box field
  8533.         * @param string $name field name
  8534.         * @param int $w width
  8535.         * @param int $h height
  8536.         * @param array $values array containing the list of values.
  8537.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8538.         * @access public
  8539.         * @author Denis Van Nuffelen, Nicola Asuni
  8540.         * @since 2.1.002 (2008-02-12)
  8541.         */
  8542.         public function ComboBox($name$w$h$values$prop=array()) {
  8543.             $this->_addfield('combobox'$name$this->x$this->y$w$h$prop);
  8544.             $s '';
  8545.             foreach ($values as $value{
  8546.                 $s .= "'".addslashes($value)."',";
  8547.             }
  8548.             $this->javascript .= 'f'.$name.'.setItems(['.substr($s0-1)."]);\n";
  8549.         }
  8550.         
  8551.         /*
  8552.         * Creates a CheckBox field
  8553.         * @param string $name field name
  8554.         * @param int $w width
  8555.         * @param boolean $checked define the initial state (default = false).
  8556.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8557.         * @access public
  8558.         * @author Denis Van Nuffelen, Nicola Asuni
  8559.         * @since 2.1.002 (2008-02-12)
  8560.         */
  8561.         public function CheckBox($name$w$checked=false$prop=array()) {
  8562.             $prop['value'($checked 'Yes' 'Off');
  8563.             if (!isset($prop['strokeColor'])) {
  8564.                 $prop['strokeColor''black';
  8565.             }
  8566.             $this->_addfield('checkbox'$name$this->x$this->y$w$w$prop);
  8567.         }
  8568.         
  8569.         /*
  8570.         * Creates a button field
  8571.         * @param string $name field name
  8572.         * @param int $w width
  8573.         * @param int $h height
  8574.         * @param string $caption caption.
  8575.         * @param string $action action triggered by the button (JavaScript code).
  8576.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8577.         * @access public
  8578.         * @author Denis Van Nuffelen, Nicola Asuni
  8579.         * @since 2.1.002 (2008-02-12)
  8580.         */
  8581.         public function Button($name$w$h$caption$action$prop=array()) {
  8582.             if (!isset($prop['strokeColor'])) {
  8583.                 $prop['strokeColor''black';
  8584.             }
  8585.             if (!isset($prop['borderStyle'])) {
  8586.                 $prop['borderStyle''beveled';
  8587.             }
  8588.             $this->_addfield('button'$name$this->x$this->y$w$h$prop);
  8589.             $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  8590.             $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  8591.             $this->javascript .= 'f'.$name.".highlight='push';\n";
  8592.             $this->javascript .= 'f'.$name.".print=false;\n";
  8593.         }
  8594.         
  8595.         // END JAVASCRIPT - FORMS ------------------------------
  8596.         
  8597.         /*
  8598.         * Enable Write permissions for PDF Reader.
  8599.         * @access protected
  8600.         * @author Nicola Asuni
  8601.         * @since 2.9.000 (2008-03-26)
  8602.         */
  8603.         protected function _putuserrights({
  8604.             if (!$this->ur{
  8605.                 return;
  8606.             }
  8607.             $this->_out('/Perms');
  8608.             $this->_out('<<');
  8609.             $this->_out('/UR3');
  8610.             $this->_out('<<');
  8611.             //$this->_out('/SubFilter/adbe.pkcs7.detached/Filter/Adobe.PPKLite/Contents');
  8612.             //$this->_out('<0>');
  8613.             //$this->_out('/ByteRange[0 3]');
  8614.             $this->_out('/M '.$this->_datastring('D:'.date('YmdHis')));
  8615.             $this->_out('/Name(TCPDF)');
  8616.             $this->_out('/Reference[');
  8617.             $this->_out('<<');
  8618.             $this->_out('/TransformParams');
  8619.             $this->_out('<<');
  8620.             $this->_out('/Type/TransformParams');
  8621.             $this->_out('/V/2.2');
  8622.             if (!empty($this->ur_document)) {
  8623.                 $this->_out('/Document['.$this->ur_document.']');
  8624.             }
  8625.             if (!empty($this->ur_annots)) {
  8626.                 $this->_out('/Annots['.$this->ur_annots.']');
  8627.             }
  8628.             if (!empty($this->ur_form)) {
  8629.                 $this->_out('/Form['.$this->ur_form.']');
  8630.             }
  8631.             if (!empty($this->ur_signature)) {
  8632.                 $this->_out('/Signature['.$this->ur_signature.']');
  8633.             }            
  8634.             $this->_out('>>');
  8635.             $this->_out('/TransformMethod/UR3');
  8636.             $this->_out('/Type/SigRef');
  8637.             $this->_out('>>');
  8638.             $this->_out(']');
  8639.             $this->_out('/Type/Sig');
  8640.             $this->_out('>>');
  8641.             $this->_out('>>');
  8642.         }
  8643.         
  8644.         /*
  8645.         * Set User's Rights for PDF Reader
  8646.         * Check the PDF Reference 8.7.1 Transform Methods, 
  8647.         * Table 8.105 Entries in the UR transform parameters dictionary
  8648.         * @param boolean $enable if true enable user's rights on PDF reader
  8649.         * @param string $document Names specifying additional document-wide usage rights for the document. The only defined value is "/FullSave", which permits a user to save the document along with modified form and/or annotation data.
  8650.         * @param string $annots Names specifying additional annotation-related usage rights for the document. Valid names in PDF 1.5 and later are /Create/Delete/Modify/Copy/Import/Export, which permit the user to perform the named operation on annotations.
  8651.         * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate 
  8652.         * @param string $signature Names specifying additional signature-related usage rights for the document. The only defined value is /Modify, which permits a user to apply a digital signature to an existing signature form field or clear a signed signature form field.
  8653.         * @access public
  8654.         * @author Nicola Asuni
  8655.         * @since 2.9.000 (2008-03-26)
  8656.         */
  8657.         public function setUserRights(
  8658.                 $enable=true
  8659.                 $document='/FullSave',
  8660.                 $annots='/Create/Delete/Modify/Copy/Import/Export',
  8661.                 $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  8662.                 $signature='/Modify'{
  8663.             $this->ur $enable;
  8664.             $this->ur_document $document;
  8665.             $this->ur_annots $annots;
  8666.             $this->ur_form $form;
  8667.             $this->ur_signature $signature;
  8668.         }
  8669.         
  8670.         /*
  8671.         * Create a new page group.
  8672.         * NOTE: call this function before calling AddPage()
  8673.         * @param int $page starting group page (leave empty for next page).
  8674.         * @access public
  8675.         * @since 3.0.000 (2008-03-27)
  8676.         */
  8677.         public function startPageGroup($page=''{
  8678.             if (empty($page)) {
  8679.                 $page $this->page 1;
  8680.             }
  8681.             $this->newpagegroup[$pagetrue;
  8682.         }
  8683.         
  8684.         /**
  8685.         * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
  8686.         * @param string $alias The alias. Default value: {nb}.
  8687.         * @since 1.4
  8688.         * @see getAliasNbPages(), PageNo(), Footer()
  8689.         */
  8690.         public function AliasNbPages($alias='{nb}'{
  8691.             //Define an alias for total number of pages
  8692.             $this->AliasNbPages = $alias;
  8693.         }
  8694.         
  8695.         /**
  8696.          * Returns the string alias used for the total number of pages.
  8697.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  8698.          * @return string 
  8699.          * @since 4.0.018 (2008-08-08)
  8700.          * @see AliasNbPages(), PageNo(), Footer()
  8701.         */
  8702.         public function getAliasNbPages({
  8703.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  8704.                 return '{'.$this->AliasNbPages.'}';
  8705.             }
  8706.             return $this->AliasNbPages;
  8707.         }
  8708.         
  8709.         /**
  8710.         * Defines an alias for the page number. It will be substituted as the document is closed.<br />
  8711.         * @param string $alias The alias. Default value: {nb}.
  8712.         * @since 4.5.000 (2009-01-02)
  8713.         * @see getAliasNbPages(), PageNo(), Footer()
  8714.         */
  8715.         public function AliasNumPage($alias='{pnb}'{
  8716.             //Define an alias for total number of pages
  8717.             $this->AliasNumPage = $alias;
  8718.         }
  8719.         
  8720.         /**
  8721.          * Returns the string alias used for the page number.
  8722.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  8723.          * @return string 
  8724.          * @since 4.5.000 (2009-01-02)
  8725.          * @see AliasNbPages(), PageNo(), Footer()
  8726.         */
  8727.         public function getAliasNumPage({
  8728.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  8729.                 return '{'.$this->AliasNumPage.'}';
  8730.             }
  8731.             return $this->AliasNumPage;
  8732.         }
  8733.         
  8734.         /*
  8735.         * Return the current page in the group.
  8736.         * @return current page in the group
  8737.         * @access public
  8738.         * @since 3.0.000 (2008-03-27)
  8739.         */
  8740.         public function getGroupPageNo({
  8741.             return $this->pagegroups[$this->currpagegroup];
  8742.         }
  8743.         
  8744.         /**
  8745.         * Returns the current group page number formatted as a string.
  8746.         * @access public
  8747.         * @since 4.3.003 (2008-11-18)
  8748.         * @see PaneNo(), formatPageNumber()
  8749.         */
  8750.         public function getGroupPageNoFormatted({
  8751.             return $this->formatPageNumber($this->getGroupPageNo());
  8752.         }
  8753.         
  8754.         /*
  8755.          * Return the alias of the current page group
  8756.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  8757.          * (will be replaced by the total number of pages in this group).
  8758.          * @return alias of the current page group
  8759.          * @access public
  8760.          * @since 3.0.000 (2008-03-27)
  8761.         */
  8762.         public function getPageGroupAlias({
  8763.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  8764.                 return '{'.$this->currpagegroup.'}';
  8765.             }
  8766.             return $this->currpagegroup;
  8767.         }
  8768.         
  8769.         /*
  8770.          * Return the alias for the page number on the current page group
  8771.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  8772.          * (will be replaced by the total number of pages in this group).
  8773.          * @return alias of the current page group
  8774.          * @access public
  8775.          * @since 4.5.000 (2009-01-02)
  8776.         */
  8777.         public function getPageNumGroupAlias({
  8778.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  8779.                 return '{'.str_replace('{nb''{pnb'$this->currpagegroup).'}';
  8780.             }
  8781.             return str_replace('{nb''{pnb'$this->currpagegroup);
  8782.         }
  8783.         
  8784.         /**
  8785.         * Format the page numbers.
  8786.         * This method can be overriden for custom formats.
  8787.         * @param int $num page number
  8788.         * @access protected
  8789.         * @since 4.2.005 (2008-11-06)
  8790.         */
  8791.         protected function formatPageNumber($num{
  8792.             return number_format((float)$num0'''.');
  8793.         }
  8794.         
  8795.         /**
  8796.         * Format the page numbers on the Table Of Content.
  8797.         * This method can be overriden for custom formats.
  8798.         * @param int $num page number
  8799.         * @access protected
  8800.         * @since 4.5.001 (2009-01-04)
  8801.         * @see addTOC()
  8802.         */
  8803.         protected function formatTOCPageNumber($num{
  8804.             return number_format((float)$num0'''.');
  8805.         }
  8806.         
  8807.         /**
  8808.         * Returns the current page number formatted as a string.
  8809.         * @access public
  8810.         * @since 4.2.005 (2008-11-06)
  8811.         * @see PaneNo(), formatPageNumber()
  8812.         */
  8813.         public function PageNoFormatted({
  8814.             return $this->formatPageNumber($this->PageNo());
  8815.         }
  8816.         
  8817.         /*
  8818.         * Put visibility settings.
  8819.         * @access protected
  8820.         * @since 3.0.000 (2008-03-27)
  8821.         */
  8822.         protected function _putocg({
  8823.             $this->_newobj();
  8824.             $this->n_ocg_print $this->n;
  8825.             $this->_out('<</Type /OCG /Name '.$this->_textstring('print'));
  8826.             $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
  8827.             $this->_out('endobj');
  8828.             $this->_newobj();
  8829.             $this->n_ocg_view=$this->n;
  8830.             $this->_out('<</Type /OCG /Name '.$this->_textstring('view'));
  8831.             $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
  8832.             $this->_out('endobj');
  8833.         }
  8834.         
  8835.         /*
  8836.         * Set the visibility of the successive elements.
  8837.         * This can be useful, for instance, to put a background 
  8838.         * image or color that will show on screen but won't print.
  8839.         * @param string $v visibility mode. Legal values are: all, print, screen.
  8840.         * @access public
  8841.         * @since 3.0.000 (2008-03-27)
  8842.         */
  8843.         public function setVisibility($v{
  8844.             if ($this->openMarkedContent{
  8845.                 // close existing open marked-content
  8846.                 $this->_out('EMC');
  8847.                 $this->openMarkedContent false;
  8848.             }
  8849.             switch($v{
  8850.                 case 'print'{
  8851.                     $this->_out('/OC /OC1 BDC');
  8852.                     $this->openMarkedContent true;
  8853.                     break;
  8854.                 }
  8855.                 case 'screen'{
  8856.                     $this->_out('/OC /OC2 BDC');
  8857.                     $this->openMarkedContent true;
  8858.                     break;
  8859.                 }
  8860.                 case 'all'{
  8861.                     $this->_out('');
  8862.                     break;
  8863.                 }
  8864.                 default{
  8865.                     $this->Error('Incorrect visibility: '.$v);
  8866.                     break;
  8867.                 }
  8868.             }
  8869.             $this->visibility $v;
  8870.         }
  8871.         
  8872.         /*
  8873.         * Add transparency parameters to the current extgstate
  8874.         * @param array $params parameters
  8875.         * @return the number of extgstates
  8876.         * @access protected
  8877.         * @since 3.0.000 (2008-03-27)
  8878.         */
  8879.         protected function addExtGState($parms{
  8880.             $n count($this->extgstates1;
  8881.             $this->extgstates[$n]['parms'$parms;
  8882.             return $n;
  8883.         }
  8884.         
  8885.         /*
  8886.         * Add an extgstate
  8887.         * @param array $gs extgstate
  8888.         * @access protected
  8889.         * @since 3.0.000 (2008-03-27)
  8890.         */
  8891.         protected function setExtGState($gs{
  8892.             $this->_out(sprintf('/GS%d gs'$gs));
  8893.         }
  8894.         
  8895.         /*
  8896.         * Put extgstates for object transparency
  8897.         * @param array $gs extgstate
  8898.         * @access protected
  8899.         * @since 3.0.000 (2008-03-27)
  8900.         */
  8901.         protected function _putextgstates({
  8902.             $ne count($this->extgstates);
  8903.             for ($i 1$i <= $ne++$i{
  8904.                 $this->_newobj();
  8905.                 $this->extgstates[$i]['n'$this->n;
  8906.                 $this->_out('<</Type /ExtGState');
  8907.                 foreach ($this->extgstates[$i]['parms'as $k => $v{
  8908.                     $this->_out('/'.$k.' '.$v);
  8909.                 }
  8910.                 $this->_out('>>');
  8911.                 $this->_out('endobj');
  8912.             }
  8913.         }
  8914.         
  8915.         /*
  8916.         * Set alpha for stroking (CA) and non-stroking (ca) operations.
  8917.         * @param float $alpha real value from 0 (transparent) to 1 (opaque)
  8918.         * @param string $bm blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  8919.         * @access public
  8920.         * @since 3.0.000 (2008-03-27)
  8921.         */
  8922.         public function setAlpha($alpha$bm='Normal'{
  8923.             $gs $this->addExtGState(array('ca' => $alpha'CA' => $alpha'BM' => '/'.$bm));
  8924.             $this->setExtGState($gs);
  8925.         }
  8926.  
  8927.         /*
  8928.         * Set the default JPEG compression quality (1-100)
  8929.         * @param int $quality JPEG quality, integer between 1 and 100
  8930.         * @access public
  8931.         * @since 3.0.000 (2008-03-27)
  8932.         */
  8933.         public function setJPEGQuality($quality{
  8934.             if (($quality 1OR ($quality 100)) {
  8935.                 $quality 75;
  8936.             }
  8937.             $this->jpeg_quality intval($quality);
  8938.         }
  8939.         
  8940.         /*
  8941.         * Set the default number of columns in a row for HTML tables.
  8942.         * @param int $cols number of columns
  8943.         * @access public
  8944.         * @since 3.0.014 (2008-06-04)
  8945.         */
  8946.         public function setDefaultTableColumns($cols=4
  8947.             $this->default_table_columns intval($cols)
  8948.         }
  8949.         
  8950.         /*
  8951.         * Set the height of cell repect font height.
  8952.         * @param int $h cell proportion respect font height (typical value = 1.25).
  8953.         * @access public
  8954.         * @since 3.0.014 (2008-06-04)
  8955.         */
  8956.         public function setCellHeightRatio($h
  8957.             $this->cell_height_ratio $h
  8958.         }
  8959.         
  8960.         /*
  8961.         * return the height of cell repect font height.
  8962.         * @access public
  8963.         * @since 4.0.012 (2008-07-24)
  8964.         */
  8965.         public function getCellHeightRatio(
  8966.             return $this->cell_height_ratio
  8967.         }
  8968.         
  8969.         /*
  8970.         * Set the PDF version (check PDF reference for valid values).
  8971.         * Default value is 1.t
  8972.         * @access public
  8973.         * @since 3.1.000 (2008-06-09)
  8974.         */
  8975.         public function setPDFVersion($version='1.7'
  8976.             $this->PDFVersion $version;
  8977.         }
  8978.         
  8979.         /*
  8980.         * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  8981.         * (see Section 8.1 of PDF reference, "Viewer Preferences").
  8982.         * <ul>
  8983.         * <li>HideToolbar boolean (Optional) A flag specifying whether to hide the viewer application's tool bars when the document is active. Default value: false.</li>
  8984.         * <li>HideMenubar boolean (Optional) A flag specifying whether to hide the viewer application's menu bar when the document is active. Default value: false.</li>
  8985.         * <li>HideWindowUI boolean (Optional) A flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed. Default value: false.</li>
  8986.         * <li>FitWindow boolean (Optional) A flag specifying whether to resize the document's window to fit the size of the first displayed page. Default value: false.</li>
  8987.         * <li>CenterWindow boolean (Optional) A flag specifying whether to position the document's window in the center of the screen. Default value: false.</li>
  8988.         * <li>DisplayDocTitle boolean (Optional; PDF 1.4) A flag specifying whether the window's title bar should display the document title taken from the Title entry of the document information dictionary (see Section 10.2.1, "Document Information Dictionary"). If false, the title bar should instead display the name of the PDF file containing the document. Default value: false.</li>
  8989.         * <li>NonFullScreenPageMode name (Optional) The document's page mode, specifying how to display the document on exiting full-screen mode:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>UseOC Optional content group panel visible</li><ul>This entry is meaningful only if the value of the PageMode entry in the catalog dictionary (see Section 3.6.1, "Document Catalog") is FullScreen; it is ignored otherwise. Default value: UseNone.</li>
  8990.         * <li>ViewArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be displayed when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  8991.         * <li>ViewClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  8992.         * <li>PrintArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be rendered when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  8993.         * <li>PrintClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  8994.         * <li>PrintScaling name (Optional; PDF 1.6) The page scaling option to be selected when a print dialog is displayed for this document. Valid values are: <ul><li>None, which indicates that the print dialog should reflect no page scaling</li><li>AppDefault (default), which indicates that applications should use the current print scaling</li><ul></li>
  8995.         * <li>Duplex name (Optional; PDF 1.7) The paper handling option to use when printing the file from the print dialog. The following values are valid:<ul><li>Simplex - Print single-sided</li><li>DuplexFlipShortEdge - Duplex and flip on the short edge of the sheet</li><li>DuplexFlipLongEdge - Duplex and flip on the long edge of the sheet</li></ul>Default value: none</li>
  8996.         * <li>PickTrayByPDFSize boolean (Optional; PDF 1.7) A flag specifying whether the PDF page size is used to select the input paper tray. This setting influences only the preset values used to populate the print dialog presented by a PDF viewer application. If PickTrayByPDFSize is true, the check box in the print dialog associated with input paper tray is checked. Note: This setting has no effect on Mac OS systems, which do not provide the ability to pick the input tray by size.</li>
  8997.         * <li>PrintPageRange array (Optional; PDF 1.7) The page numbers used to initialize the print dialog box when the file is printed. The first page of the PDF file is denoted by 1. Each pair consists of the first and last pages in the sub-range. An odd number of integers causes this entry to be ignored. Negative numbers cause the entire array to be ignored. Default value: as defined by PDF viewer application</li>
  8998.         * <li>NumCopies integer (Optional; PDF 1.7) The number of copies to be printed when the print dialog is opened for this file. Supported values are the integers 2 through 5. Values outside this range are ignored. Default value: as defined by PDF viewer application, but typically 1</li>
  8999.         * </ul>
  9000.         * @param array $preferences array of options.
  9001.         * @author Nicola Asuni
  9002.         * @access public
  9003.         * @since 3.1.000 (2008-06-09)
  9004.         */
  9005.         public function setViewerPreferences($preferences
  9006.             $this->viewer_preferences $preferences;
  9007.         }
  9008.         
  9009.         /**
  9010.         * Paints a linear colour gradient.
  9011.         * @param float $x abscissa of the top left corner of the rectangle.
  9012.         * @param float $y ordinate of the top left corner of the rectangle.
  9013.         * @param float $w width of the rectangle.
  9014.         * @param float $h height of the rectangle.
  9015.         * @param array $col1 first color (RGB components).
  9016.         * @param array $col2 second color (RGB components).
  9017.         * @param array $coords array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  9018.         * @author Andreas Würmser, Nicola Asuni
  9019.         * @since 3.1.000 (2008-06-09)
  9020.         * @access public
  9021.         */
  9022.         public function LinearGradient($x$y$w$h$col1=array()$col2=array()$coords=array(0,0,1,0)) {
  9023.             $this->Clip($x$y$w$h);
  9024.             $this->Gradient(2$col1$col2$coords);
  9025.         }
  9026.         
  9027.         /**
  9028.         * Paints a radial colour gradient.
  9029.         * @param float $x abscissa of the top left corner of the rectangle.
  9030.         * @param float $y ordinate of the top left corner of the rectangle.
  9031.         * @param float $w width of the rectangle.
  9032.         * @param float $h height of the rectangle.
  9033.         * @param array $col1 first color (RGB components).
  9034.         * @param array $col2 second color (RGB components).
  9035.         * @param array $coords array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined.
  9036.         * @author Andreas Würmser, Nicola Asuni
  9037.         * @since 3.1.000 (2008-06-09)
  9038.         * @access public
  9039.         */
  9040.         public function RadialGradient($x$y$w$h$col1=array()$col2=array()$coords=array(0.5,0.5,0.5,0.5,1)) {
  9041.             $this->Clip($x$y$w$h);
  9042.             $this->Gradient(3$col1$col2$coords);
  9043.         }
  9044.         
  9045.         /**
  9046.         * Paints a coons patch mesh.
  9047.         * @param float $x abscissa of the top left corner of the rectangle.
  9048.         * @param float $y ordinate of the top left corner of the rectangle.
  9049.         * @param float $w width of the rectangle.
  9050.         * @param float $h height of the rectangle.
  9051.         * @param array $col1 first color (lower left corner) (RGB components).
  9052.         * @param array $col2 second color (lower right corner) (RGB components).
  9053.         * @param array $col3 third color (upper right corner) (RGB components).
  9054.         * @param array $col4 fourth color (upper left corner) (RGB components).
  9055.         * @param array $coords <ul><li>for one patch mesh: array(float x1, float y1, .... float x12, float y12): 12 pairs of coordinates (normally from 0 to 1) which specify the Bezier control points that define the patch. First pair is the lower left edge point, next is its right control point (control point 2). Then the other points are defined in the order: control point 1, edge point, control point 2 going counter-clockwise around the patch. Last (x12, y12) is the first edge point's left control point (control point 1).</li><li>for two or more patch meshes: array[number of patches]: arrays with the following keys for each patch: f: where to put that patch (0 = first patch, 1, 2, 3 = right, top and left of precedent patch - I didn't figure this out completely - just try and error ;-) points: 12 pairs of coordinates of the Bezier control points as above for the first patch, 8 pairs of coordinates for the following patches, ignoring the coordinates already defined by the precedent patch (I also didn't figure out the order of these - also: try and see what's happening) colors: must be 4 colors for the first patch, 2 colors for the following patches</li></ul>
  9056.         * @param array $coords_min minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
  9057.         * @param array $coords_max maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
  9058.         * @author Andreas Würmser, Nicola Asuni
  9059.         * @since 3.1.000 (2008-06-09)
  9060.         * @access public
  9061.         */
  9062.         public function CoonsPatchMesh($x$y$w$h$col1=array()$col2=array()$col3=array()$col4=array()$coords=array(0.00,0.0,0.33,0.00,0.67,0.00,1.00,0.00,1.00,0.33,1.00,0.67,1.00,1.00,0.67,1.00,0.33,1.00,0.00,1.00,0.00,0.67,0.00,0.33)$coords_min=0$coords_max=1{
  9063.             $this->Clip($x$y$w$h);        
  9064.             $n count($this->gradients1;
  9065.             $this->gradients[$n]['type'6//coons patch mesh
  9066.             //check the coords array if it is the simple array or the multi patch array
  9067.             if (!isset($coords[0]['f'])) {
  9068.                 //simple array -> convert to multi patch array
  9069.                 if (!isset($col1[1])) {
  9070.                     $col1[1$col1[2$col1[0];
  9071.                 }
  9072.                 if (!isset($col2[1])) {
  9073.                     $col2[1$col2[2$col2[0];
  9074.                 }
  9075.                 if (!isset($col3[1])) {
  9076.                     $col3[1$col3[2$col3[0];
  9077.                 }
  9078.                 if (!isset($col4[1])) {
  9079.                     $col4[1$col4[2$col4[0];
  9080.                 }
  9081.                 $patch_array[0]['f'0;
  9082.                 $patch_array[0]['points'$coords;
  9083.                 $patch_array[0]['colors'][0]['r'$col1[0];
  9084.                 $patch_array[0]['colors'][0]['g'$col1[1];
  9085.                 $patch_array[0]['colors'][0]['b'$col1[2];
  9086.                 $patch_array[0]['colors'][1]['r'$col2[0];
  9087.                 $patch_array[0]['colors'][1]['g'$col2[1];
  9088.                 $patch_array[0]['colors'][1]['b'$col2[2];
  9089.                 $patch_array[0]['colors'][2]['r'$col3[0];
  9090.                 $patch_array[0]['colors'][2]['g'$col3[1];
  9091.                 $patch_array[0]['colors'][2]['b'$col3[2];
  9092.                 $patch_array[0]['colors'][3]['r'$col4[0];
  9093.                 $patch_array[0]['colors'][3]['g'$col4[1];
  9094.                 $patch_array[0]['colors'][3]['b'$col4[2];
  9095.             else {
  9096.                 //multi patch array
  9097.                 $patch_array $coords;
  9098.             }
  9099.             $bpcd 65535//16 BitsPerCoordinate
  9100.             //build the data stream
  9101.             $this->gradients[$n]['stream''';
  9102.             $count_patch count($patch_array);
  9103.             for($i=0$i $count_patch++$i{
  9104.                 $this->gradients[$n]['stream'.= chr($patch_array[$i]['f'])//start with the edge flag as 8 bit
  9105.                 $count_points count($patch_array[$i]['points']);
  9106.                 for($j=0$j $count_points++$j{
  9107.                     //each point as 16 bit
  9108.                     $patch_array[$i]['points'][$j(($patch_array[$i]['points'][$j$coords_min($coords_max $coords_min)) $bpcd;
  9109.                     if ($patch_array[$i]['points'][$j0{
  9110.                         $patch_array[$i]['points'][$j0;
  9111.                     }
  9112.                     if ($patch_array[$i]['points'][$j$bpcd{
  9113.                         $patch_array[$i]['points'][$j$bpcd;
  9114.                     }
  9115.                     $this->gradients[$n]['stream'.= chr(floor($patch_array[$i]['points'][$j256));
  9116.                     $this->gradients[$n]['stream'.= chr(floor($patch_array[$i]['points'][$j256));
  9117.                 }
  9118.                 $count_cols count($patch_array[$i]['colors']);
  9119.                 for($j=0$j $count_cols++$j{
  9120.                     //each color component as 8 bit
  9121.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['r']);
  9122.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['g']);
  9123.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['b']);
  9124.                 }
  9125.             }
  9126.             //paint the gradient
  9127.             $this->_out('/Sh'.$n.' sh');
  9128.             //restore previous Graphic State
  9129.             $this->_out('Q');
  9130.         }
  9131.         
  9132.         /**
  9133.         * Set a rectangular clipping area.
  9134.         * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  9135.         * @param float $y ordinate of the top left corner of the rectangle.
  9136.         * @param float $w width of the rectangle.
  9137.         * @param float $h height of the rectangle.
  9138.         * @author Andreas Würmser, Nicola Asuni
  9139.         * @since 3.1.000 (2008-06-09)
  9140.         * @access protected
  9141.         */
  9142.         protected function Clip($x$y$w$h{
  9143.             if ($this->rtl{
  9144.                 $x $this->w $x $w;
  9145.             }
  9146.             //save current Graphic State
  9147.             $s 'q';
  9148.             //set clipping area
  9149.             $s .= sprintf(' %.2f %.2f %.2f %.2f re W n'$x*$this->k($this->h-$y)*$this->k$w*$this->k-$h*$this->k);
  9150.             //set up transformation matrix for gradient
  9151.             $s .= sprintf(' %.3f 0 0 %.3f %.3f %.3f cm'$w*$this->k$h*$this->k$x*$this->k($this->h-($y+$h))*$this->k);
  9152.             $this->_out($s);
  9153.         }
  9154.                 
  9155.         /**
  9156.         * Output gradient.
  9157.         * @param int $type type of gradient.
  9158.         * @param array $col1 first color (RGB components).
  9159.         * @param array $col2 second color (RGB components).
  9160.         * @param array $coords array of coordinates.
  9161.         * @author Andreas Würmser, Nicola Asuni
  9162.         * @since 3.1.000 (2008-06-09)
  9163.         * @access protected
  9164.         */
  9165.         protected function Gradient($type$col1$col2$coords{
  9166.             $n count($this->gradients1;
  9167.             $this->gradients[$n]['type'$type;
  9168.             if (!isset($col1[1])) {
  9169.                 $col1[1]=$col1[2]=$col1[0];
  9170.             }
  9171.             $this->gradients[$n]['col1'sprintf('%.3f %.3f %.3f'($col1[0]/255)($col1[1]/255)($col1[2]/255));
  9172.             if (!isset($col2[1])) {
  9173.                 $col2[1$col2[2$col2[0];
  9174.             }
  9175.             $this->gradients[$n]['col2'sprintf('%.3f %.3f %.3f'($col2[0]/255)($col2[1]/255)($col2[2]/255));
  9176.             $this->gradients[$n]['coords'$coords;
  9177.             //paint the gradient
  9178.             $this->_out('/Sh'.$n.' sh');
  9179.             //restore previous Graphic State
  9180.             $this->_out('Q');
  9181.         }
  9182.         
  9183.         /**
  9184.         * Output shaders.
  9185.         * @author Andreas Würmser, Nicola Asuni
  9186.         * @since 3.1.000 (2008-06-09)
  9187.         * @access protected
  9188.         */
  9189.         function _putshaders({
  9190.             foreach ($this->gradients as $id => $grad{  
  9191.                 if (($grad['type'== 2OR ($grad['type'== 3)) {
  9192.                     $this->_newobj();
  9193.                     $this->_out('<<');
  9194.                     $this->_out('/FunctionType 2');
  9195.                     $this->_out('/Domain [0.0 1.0]');
  9196.                     $this->_out('/C0 ['.$grad['col1'].']');
  9197.                     $this->_out('/C1 ['.$grad['col2'].']');
  9198.                     $this->_out('/N 1');
  9199.                     $this->_out('>>');
  9200.                     $this->_out('endobj');
  9201.                     $f1 $this->n;
  9202.                 }
  9203.                 $this->_newobj();
  9204.                 $this->_out('<<');
  9205.                 $this->_out('/ShadingType '.$grad['type']);
  9206.                 $this->_out('/ColorSpace /DeviceRGB');
  9207.                 if ($grad['type'== 2{
  9208.                     $this->_out(sprintf('/Coords [%.3f %.3f %.3f %.3f]'$grad['coords'][0]$grad['coords'][1]$grad['coords'][2]$grad['coords'][3]));
  9209.                     $this->_out('/Function '.$f1.' 0 R');
  9210.                     $this->_out('/Extend [true true] ');
  9211.                     $this->_out('>>');
  9212.                 elseif ($grad['type'== 3{
  9213.                     //x0, y0, r0, x1, y1, r1
  9214.                     //at this this time radius of inner circle is 0
  9215.                     $this->_out(sprintf('/Coords [%.3f %.3f 0 %.3f %.3f %.3f]'$grad['coords'][0]$grad['coords'][1]$grad['coords'][2]$grad['coords'][3]$grad['coords'][4]));
  9216.                     $this->_out('/Function '.$f1.' 0 R');
  9217.                     $this->_out('/Extend [true true] ');
  9218.                     $this->_out('>>');
  9219.                 elseif ($grad['type'== 6{
  9220.                     $this->_out('/BitsPerCoordinate 16');
  9221.                     $this->_out('/BitsPerComponent 8');
  9222.                     $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]');
  9223.                     $this->_out('/BitsPerFlag 8');
  9224.                     $this->_out('/Length '.strlen($grad['stream']));
  9225.                     $this->_out('>>');
  9226.                     $this->_putstream($grad['stream']);
  9227.                 }
  9228.                 $this->_out('endobj');
  9229.                 $this->gradients[$id]['id'$this->n;
  9230.             }
  9231.         }
  9232.  
  9233.         /**
  9234.         * Output an arc
  9235.         * @author Maxime Delorme, Nicola Asuni
  9236.         * @since 3.1.000 (2008-06-09)
  9237.         * @access protected
  9238.         */
  9239.         protected function _outarc($x1$y1$x2$y2$x3$y3 {
  9240.             $h $this->h;
  9241.             $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c'$x1*$this->k($h-$y1)*$this->k$x2*$this->k($h-$y2)*$this->k$x3*$this->k($h-$y3)*$this->k));
  9242.         }
  9243.         
  9244.         /**
  9245.         * Draw the sector of a circle.
  9246.         * It can be used for instance to render pie charts.
  9247.         * @param float $xc abscissa of the center.
  9248.         * @param float $yc ordinate of the center.
  9249.         * @param float $r radius.
  9250.         * @param float $a start angle (in degrees).
  9251.         * @param float $b end angle (in degrees).
  9252.         * @param string $style: D, F, FD or DF (draw, fill, fill and draw). Default: FD.
  9253.         * @param float $cw: indicates whether to go clockwise (default: true).
  9254.         * @param float $o: origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
  9255.         * @author Maxime Delorme, Nicola Asuni
  9256.         * @since 3.1.000 (2008-06-09)
  9257.         * @access public
  9258.         */
  9259.         public function PieSector($xc$yc$r$a$b$style='FD'$cw=true$o=90{
  9260.             if ($this->rtl{
  9261.                 $xc $this->w $xc;
  9262.             }
  9263.             if ($cw{
  9264.                 $d $b;
  9265.                 $b $o $a;
  9266.                 $a $o $d;
  9267.             else {
  9268.                 $b += $o;
  9269.                 $a += $o;
  9270.             }
  9271.             $a ($a 360360;
  9272.             $b ($b 360360;
  9273.             if ($a $b{
  9274.                 $b +=360;
  9275.             }
  9276.             $b $b 360 M_PI;
  9277.             $a $a 360 M_PI;
  9278.             $d $b $a;
  9279.             if ($d == {
  9280.                 $d M_PI;
  9281.             }
  9282.             $k $this->k;
  9283.             $hp $this->h;
  9284.             if ($style=='F'{
  9285.                 $op 'f';
  9286.             elseif ($style=='FD' or $style=='DF'{
  9287.                 $op 'b';
  9288.             else {
  9289.                 $op 's';
  9290.             }
  9291.             if (sin($d/2)) {
  9292.                 $MyArc 4/(cos($d/2)) sin($d/2$r;
  9293.             }
  9294.             //first put the center
  9295.             $this->_out(sprintf('%.2f %.2f m'($xc)*$k($hp-$yc)*$k));
  9296.             //put the first point
  9297.             $this->_out(sprintf('%.2f %.2f l'($xc+$r*cos($a))*$k(($hp-($yc-$r*sin($a)))*$k)));
  9298.             //draw the arc
  9299.             if ($d (M_PI/2)) {
  9300.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  9301.             else {
  9302.                 $b $a $d/4;
  9303.                 $MyArc 4/3*(1-cos($d/8))/sin($d/8)*$r;
  9304.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  9305.                 $a $b;
  9306.                 $b $a $d/4;
  9307.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  9308.                 $a $b;
  9309.                 $b $a $d/4;
  9310.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b) );
  9311.                 $a $b;
  9312.                 $b $a $d/4;
  9313.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  9314.             }
  9315.             //terminate drawing
  9316.             $this->_out($op);
  9317.         }
  9318.         
  9319.         /**
  9320.         * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  9321.         * Only vector drawing is supported, not text or bitmap.
  9322.         * Although the script was successfully tested with various AI format versions, best results are probably achieved with files that were exported in the AI3 format (tested with Illustrator CS2, Freehand MX and Photoshop CS2).
  9323.         * @param string $file Name of the file containing the image.
  9324.         * @param float $x Abscissa of the upper-left corner.
  9325.         * @param float $y Ordinate of the upper-left corner.
  9326.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9327.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9328.         * @param mixed $link URL or identifier returned by AddLink().
  9329.         * @param boolean useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  9330.         * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  9331.         * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  9332.         * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  9333.         * @author Valentin Schmidt, Nicola Asuni
  9334.         * @since 3.1.000 (2008-06-09)
  9335.         * @access public
  9336.         */
  9337.         public function ImageEps($file$x=''$y=''$w=0$h=0$link=''$useBoundingBox=true$align=''$palign=''$border=0{
  9338.             if ($x === ''{
  9339.                 $x $this->x;
  9340.             }
  9341.             if ($y === ''{
  9342.                 $y $this->y;
  9343.             }
  9344.             $k $this->k;
  9345.             $data file_get_contents($file);
  9346.             if ($data === false{
  9347.                 $this->Error('EPS file not found: '.$file);
  9348.             }
  9349.             $regs array();
  9350.             // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  9351.             preg_match("/%%Creator:([^\r\n]+)/"$data$regs)# find Creator
  9352.             if (count($regs1{
  9353.                 $version_str trim($regs[1])# e.g. "Adobe Illustrator(R) 8.0"
  9354.                 if (strpos($version_str'Adobe Illustrator'!== false{
  9355.                     $versexp explode(' '$version_str);
  9356.                     $version = (float)array_pop($versexp);
  9357.                     if ($version >= 9{
  9358.                         $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  9359.                     }
  9360.                 }
  9361.             }
  9362.             // strip binary bytes in front of PS-header
  9363.             $start strpos($data'%!PS-Adobe');
  9364.             if ($start 0{
  9365.                 $data substr($data$start);
  9366.             }
  9367.             // find BoundingBox params
  9368.             preg_match("/%%BoundingBox:([^\r\n]+)/"$data$regs);
  9369.             if (count($regs1{
  9370.                 list($x1$y1$x2$y2explode(' 'trim($regs[1]));
  9371.             else {
  9372.                 $this->Error('No BoundingBox found in EPS file: '.$file);
  9373.             }
  9374.             $start strpos($data'%%EndSetup');
  9375.             if ($start === false{
  9376.                 $start strpos($data'%%EndProlog');
  9377.             }
  9378.             if ($start === false{
  9379.                 $start strpos($data'%%BoundingBox');
  9380.             }
  9381.             $data substr($data$start);
  9382.             $end strpos($data'%%PageTrailer');
  9383.             if ($end===false{
  9384.                 $end strpos($data'showpage');
  9385.             }
  9386.             if ($end{
  9387.                 $data substr($data0$end);
  9388.             }
  9389.             if ($w 0{
  9390.                 $scale_x $w (($x2 $x1$k);
  9391.                 if ($h 0{
  9392.                     $scale_y $h (($y2 $y1$k);
  9393.                 else {
  9394.                     $scale_y $scale_x;
  9395.                     $h ($y2 $y1$k $scale_y;
  9396.                 }
  9397.             else {
  9398.                 if ($h 0{
  9399.                     $scale_y $h (($y2 $y1$k);
  9400.                     $scale_x $scale_y;
  9401.                     $w ($x2-$x1$k $scale_x;
  9402.                 else {
  9403.                     $w ($x2 $x1$k;
  9404.                     $h ($y2 $y1$k;
  9405.                 }
  9406.             }
  9407.             // Check whether we need a new page first as this does not fit
  9408.             if ((($y $h$this->PageBreakTriggerAND (!$this->InFooterAND $this->AcceptPageBreak()) {
  9409.                 // Automatic page break
  9410.                 $this->AddPage($this->CurOrientation);
  9411.                 // Reset Y coordinate to the top of next page
  9412.                 $y $this->GetY($this->cMargin;
  9413.             }
  9414.             // set bottomcoordinates
  9415.             $this->img_rb_y $y $h;
  9416.             // set alignment
  9417.             if ($this->rtl{
  9418.                 if ($palign == 'L'{
  9419.                     $ximg $this->lMargin;
  9420.                     // set right side coordinate
  9421.                     $this->img_rb_x $ximg $w;
  9422.                 elseif ($palign == 'C'{
  9423.                     $ximg ($this->w $x $w2;
  9424.                     // set right side coordinate
  9425.                     $this->img_rb_x $ximg $w;
  9426.                 else {
  9427.                     $ximg $this->w $x $w;
  9428.                     // set left side coordinate
  9429.                     $this->img_rb_x $ximg;
  9430.                 }
  9431.             else {
  9432.                 if ($palign == 'R'{
  9433.                     $ximg $this->w $this->rMargin $w;
  9434.                     // set left side coordinate
  9435.                     $this->img_rb_x $ximg;
  9436.                 elseif ($palign == 'C'{
  9437.                     $ximg ($this->w $x $w2;
  9438.                     // set right side coordinate
  9439.                     $this->img_rb_x $ximg $w;
  9440.                 else {
  9441.                     $ximg $x;
  9442.                     // set right side coordinate
  9443.                     $this->img_rb_x $ximg $w;
  9444.                 }
  9445.             }
  9446.             if ($useBoundingBox{
  9447.                 $dx $ximg $k $x1;
  9448.                 $dy $y $k $y1;
  9449.             else {
  9450.                 $dx $ximg $k;
  9451.                 $dy $y $k;
  9452.             }
  9453.             // save the current graphic state
  9454.             $this->_out('q'.$this->epsmarker);
  9455.             // translate
  9456.             $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'1001$dx$dy ($this->hPt ($y $k($y2 $y1))));
  9457.             // scale
  9458.             if (isset($scale_x)) {
  9459.                 $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'$scale_x00$scale_y$x1 ($scale_x)$y2 ($scale_y)));
  9460.             }
  9461.             // handle pc/unix/mac line endings
  9462.             preg_match('/[\r\n]+/s'$data$regs);
  9463.             $lines explode($regs[0]$data);
  9464.             $u=0;
  9465.             $cnt count($lines);
  9466.             for ($i=0$i $cnt++$i{
  9467.                 $line $lines[$i];
  9468.                 if (($line == ''OR ($line{0== '%')) {
  9469.                     continue;
  9470.                 }
  9471.                 $len strlen($line);
  9472.                 $chunks explode(' '$line);
  9473.                 $cmd array_pop($chunks);
  9474.                 // RGB
  9475.                 if (($cmd == 'Xa'OR ($cmd == 'XA')) {
  9476.                     $b array_pop($chunks)
  9477.                     $g array_pop($chunks)
  9478.                     $r array_pop($chunks);
  9479.                     $this->_out(''.$r.' '.$g.' '.$b.' '.($cmd=='Xa'?'rg':'RG'))//substr($line, 0, -2).'rg' -> in EPS (AI8): c m y k r g b rg!
  9480.                     continue;
  9481.                 }
  9482.                 switch ($cmd{
  9483.                     case 'm':
  9484.                     case 'l':
  9485.                     case 'v':
  9486.                     case 'y':
  9487.                     case 'c':
  9488.                     case 'k':
  9489.                     case 'K':
  9490.                     case 'g':
  9491.                     case 'G':
  9492.                     case 's':
  9493.                     case 'S':
  9494.                     case 'J':
  9495.                     case 'j':
  9496.                     case 'w':
  9497.                     case 'M':
  9498.                     case 'd':
  9499.                     case 'n':
  9500.                     case 'v'{
  9501.                         $this->_out($line);
  9502.                         break;
  9503.                     }
  9504.                     case 'x'{// custom fill color
  9505.                         list($c,$m,$y,$k$chunks;
  9506.                         $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' k');
  9507.                         break;
  9508.                     }
  9509.                     case 'X'// custom stroke color
  9510.                         list($c,$m,$y,$k$chunks;
  9511.                         $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' K');
  9512.                         break;
  9513.                     }
  9514.                     case 'Y':
  9515.                     case 'N':
  9516.                     case 'V':
  9517.                     case 'L':
  9518.                     case 'C'{
  9519.                         $line{$len-1strtolower($cmd);
  9520.                         $this->_out($line);
  9521.                         break;
  9522.                     }
  9523.                     case 'b':
  9524.                     case 'B'{
  9525.                         $this->_out($cmd '*');
  9526.                         break;
  9527.                     }
  9528.                     case 'f':
  9529.                     case 'F'{
  9530.                         if ($u 0{
  9531.                             $isU false;
  9532.                             $max min($i+5$cnt);
  9533.                             for ($j=$i+1$j $max++$j)
  9534.                               $isU ($isU OR (($lines[$j== 'U'OR ($lines[$j== '*U')));
  9535.                             if ($isU{
  9536.                                 $this->_out('f*');
  9537.                             }
  9538.                         else {
  9539.                             $this->_out('f*');
  9540.                         }
  9541.                         break;
  9542.                     }
  9543.                     case '*u'{
  9544.                         ++$u;
  9545.                         break;
  9546.                     }
  9547.                     case '*U'{
  9548.                         --$u;
  9549.                         break;
  9550.                     }
  9551.                 }
  9552.             }
  9553.             // restore previous graphic state
  9554.             $this->_out($this->epsmarker.'Q');
  9555.             if (!empty($border)) {
  9556.                 $bx $x;
  9557.                 $by $y;
  9558.                 $this->x $x;
  9559.                 $this->y $y;
  9560.                 $this->Cell($w$h''$border0''0''0);
  9561.                 $this->x $bx;
  9562.                 $this->y $by;
  9563.             }
  9564.             if ($link{
  9565.                 $this->Link($ximg$y$w$h$link0);
  9566.             }
  9567.             // set pointer to align the successive text/objects
  9568.             switch($align{
  9569.                 case 'T':{
  9570.                     $this->y $y;
  9571.                     $this->x $this->img_rb_x;
  9572.                     break;
  9573.                 }
  9574.                 case 'M':{
  9575.                     $this->y $y round($h/2);
  9576.                     $this->x $this->img_rb_x;
  9577.                     break;
  9578.                 }
  9579.                 case 'B':{
  9580.                     $this->y $this->img_rb_y;
  9581.                     $this->x $this->img_rb_x;
  9582.                     break;
  9583.                 }
  9584.                 case 'N':{
  9585.                     $this->SetY($this->img_rb_y);
  9586.                     break;
  9587.                 }
  9588.                 default:{
  9589.                     break;
  9590.                 }
  9591.             }
  9592.             $this->endlinex $this->img_rb_x;
  9593.         }
  9594.         
  9595.         /**
  9596.           * Set document barcode.
  9597.          * @param string $bc barcode
  9598.          */
  9599.         public function setBarcode($bc=''{
  9600.             $this->barcode $bc;
  9601.         }
  9602.         
  9603.         /**
  9604.           * Get current barcode.
  9605.          * @return string 
  9606.          * @since 4.0.012 (2008-07-24)
  9607.          */
  9608.         public function getBarcode({
  9609.             return $this->barcode;
  9610.         }
  9611.         
  9612.         /**
  9613.           * Print Barcode.
  9614.           * @param string $code code to print
  9615.           * @param string $type type of barcode.
  9616.          * @param int $x x position in user units
  9617.          * @param int $y y position in user units
  9618.          * @param int $w width in user units
  9619.          * @param int $h height position in user units
  9620.          * @param float $xres width of the smallest bar in user units
  9621.          * @param array $style array of options:<ul><li>string $style['position'] barcode position inside the specified width: L = left (default for LTR); C = center; R = right (default for RTL); S = stretch</li><li>boolean $style['border'] if true prints a border around the barcode</li><li>int $style['padding'] padding to leave around the barcode in user units</li><li>array $style['fgcolor'] color array for bars and text</li><li>mixed $style['bgcolor'] color array for background or false for transparent</li><li>boolean $style["text"] boolean if true prints text below the barcode</li><li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li><li>int $style['stretchtext']: 0 = disabled; 1 = horizontal scaling only if necessary; 2 = forced horizontal scaling; 3 = character spacing only if necessary; 4 = forced character spacing</li></ul>
  9622.          * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  9623.          * @author Nicola Asuni
  9624.          * @since 3.1.000 (2008-06-09)
  9625.          * @access public
  9626.          */
  9627.         public function write1DBarcode($code$type$x=''$y=''$w=''$h=''$xres=0.4$style=''$align=''{
  9628.             if (empty($code)) {
  9629.                 return;
  9630.             }
  9631.             require_once(dirname(__FILE__).'/barcodes.php');
  9632.             // save current graphic settings
  9633.             $gvars $this->getGraphicVars();
  9634.             // create new barcode object
  9635.             $barcodeobj new TCPDFbarcode($code$type);
  9636.             $arrcode $barcodeobj->getBarcodeArray();
  9637.             if ($arrcode === false{
  9638.                 $this->Error('Error in barcode string');
  9639.             }
  9640.             // set default values
  9641.             if (!isset($style['position'])) {
  9642.                 if ($this->rtl{
  9643.                     $style['position''R';
  9644.                 else {
  9645.                     $style['position''L';
  9646.                 }
  9647.             }
  9648.             if (!isset($style['padding'])) {
  9649.                 $style['padding'0;
  9650.             }
  9651.             if (!isset($style['fgcolor'])) {
  9652.                 $style['fgcolor'array(0,0,0)// default black
  9653.             }
  9654.             if (!isset($style['bgcolor'])) {
  9655.                 $style['bgcolor'false// default transparent
  9656.             }
  9657.             if (!isset($style['border'])) {
  9658.                 $style['border'false;
  9659.             }
  9660.             if (!isset($style['text'])) {
  9661.                 $style['text'false;
  9662.                 $fontsize 0;
  9663.             }
  9664.             if ($style['text'AND isset($style['font'])) {
  9665.                 if (isset($style['fontsize'])) {
  9666.                     $fontsize $style['fontsize'];
  9667.                 else {
  9668.                     $fontsize 0;
  9669.                 }
  9670.                 $this->SetFont($style['font']''$fontsize);
  9671.             }
  9672.             if (!isset($style['stretchtext'])) {
  9673.                 $style['stretchtext'4;
  9674.             }
  9675.             // set foreground color
  9676.             $this->SetDrawColorArray($style['fgcolor']);
  9677.             $this->SetTextColorArray($style['fgcolor']);
  9678.             if (empty($wOR ($w <= 0)) {
  9679.                 if ($this->rtl{
  9680.                     $w $this->x $this->lMargin;
  9681.                 else {
  9682.                     $w $this->w $this->rMargin $this->x;
  9683.                 }
  9684.             }
  9685.             if (empty($x)) {
  9686.                 $x $this->GetX();
  9687.             }
  9688.             if ($this->rtl{
  9689.                 $x $this->w $x;
  9690.             }
  9691.             if (empty($y)) {
  9692.                 $y $this->GetY();
  9693.             }
  9694.             if (empty($xres)) {
  9695.                 $xres 0.4;
  9696.             }
  9697.             $fbw ($arrcode['maxw'$xres($style['padding']);
  9698.             $extraspace ($this->cell_height_ratio $fontsize $this->k($style['padding']);
  9699.             if (empty($h)) {
  9700.                 $h 10 $extraspace;
  9701.             }
  9702.             if ($this->checkPageBreak($h)) {
  9703.                 $y $this->y;
  9704.             }
  9705.             // maximum bar heigth
  9706.             $barh $h $extraspace;
  9707.             switch ($style['position']{
  9708.                 case 'L'// left
  9709.                     if ($this->rtl{
  9710.                         $xpos $x $w;
  9711.                     else {
  9712.                         $xpos $x;
  9713.                     }
  9714.                     break;
  9715.                 }
  9716.                 case 'C'// center
  9717.                     $xdiff (($w $fbw2);
  9718.                     if ($this->rtl{
  9719.                         $xpos $x $w $xdiff;
  9720.                     else {
  9721.                         $xpos $x $xdiff;
  9722.                     }
  9723.                     break;
  9724.                 }
  9725.                 case 'R'// right
  9726.                     if ($this->rtl{
  9727.                         $xpos $x $fbw;
  9728.                     else {
  9729.                         $xpos $x $w $fbw;
  9730.                     }
  9731.                     break;
  9732.                 }
  9733.                 case 'S'// stretch
  9734.                     $fbw $w;
  9735.                     $xres ($w ($style['padding'])) $arrcode['maxw'];
  9736.                     if ($this->rtl{
  9737.                         $xpos $x $w;
  9738.                     else {
  9739.                         $xpos $x;
  9740.                     }
  9741.                     break;
  9742.                 }
  9743.             }
  9744.             $xpos_rect $xpos;
  9745.             $xpos $xpos_rect $style['padding'];
  9746.             $xpos_text $xpos;
  9747.             // barcode is always printed in LTR direction
  9748.             $tempRTL $this->rtl;
  9749.             $this->rtl false;
  9750.             // print background color
  9751.             if ($style['bgcolor']{
  9752.                 $this->Rect($xpos_rect$y$fbw$h'DF'''$style['bgcolor']);
  9753.             elseif ($style['border']{
  9754.                 $this->Rect($xpos_rect$y$fbw$h'D');
  9755.             }
  9756.             // print bars
  9757.             if ($arrcode !== false{
  9758.                 foreach ($arrcode['bcode'as $k => $v{
  9759.                     $bw ($v['w'$xres);
  9760.                     if ($v['t']{
  9761.                         // braw a vertical bar
  9762.                         $ypos $y $style['padding'($v['p'$barh $arrcode['maxh']);
  9763.                         $this->Rect($xpos$ypos$bw($v['h'$barh  $arrcode['maxh'])'DF'array('L'=>0'T'=>0'R'=>0'B'=>0)$style['fgcolor']);
  9764.                     }
  9765.                     $xpos += $bw;
  9766.                 }
  9767.             }
  9768.             // print text
  9769.             if ($style['text']{
  9770.                 // print text
  9771.                 $this->x $xpos_text;
  9772.                 $this->y $y $style['padding'$barh
  9773.                 $this->Cell(($arrcode['maxw'$xres)($this->cell_height_ratio $fontsize $this->k)$code00'C'0''$style['stretchtext']);
  9774.             }
  9775.             // restore original direction
  9776.             $this->rtl $tempRTL;
  9777.             // restore previous settings
  9778.             $this->setGraphicVars($gvars);
  9779.             // set bottomcoordinates
  9780.             $this->img_rb_y $y $h;
  9781.             if ($this->rtl{
  9782.                 // set left side coordinate
  9783.                 $this->img_rb_x ($this->w $x $w);
  9784.             else {
  9785.                 // set right side coordinate
  9786.                 $this->img_rb_x $x $w;
  9787.             }
  9788.             // set pointer to align the successive text/objects
  9789.             switch($align{
  9790.                 case 'T':{
  9791.                     $this->y $y;
  9792.                     $this->x $this->img_rb_x;
  9793.                     break;
  9794.                 }
  9795.                 case 'M':{
  9796.                     $this->y $y round($h/2);
  9797.                     $this->x $this->img_rb_x;
  9798.                     break;
  9799.                 }
  9800.                 case 'B':{
  9801.                     $this->y $this->img_rb_y;
  9802.                     $this->x $this->img_rb_x;
  9803.                     break;
  9804.                 }
  9805.                 case 'N':{
  9806.                     $this->SetY($this->img_rb_y);
  9807.                     break;
  9808.                 }
  9809.                 default:{
  9810.                     break;
  9811.                 }
  9812.             }
  9813.         }
  9814.         
  9815.         /**
  9816.           * This function is DEPRECATED, please use the new write1DBarcode() function.
  9817.          * @param int $x x position in user units
  9818.          * @param int $y y position in user units
  9819.          * @param int $w width in user units
  9820.          * @param int $h height position in user units
  9821.          * @param string $type type of barcode (I25, C128A, C128B, C128C, C39)
  9822.          * @param string $style barcode style
  9823.          * @param string $font font for text
  9824.          * @param int $xres x resolution
  9825.          * @param string $code code to print
  9826.          * @deprecated deprecated since version 3.1.000 (2008-06-10)
  9827.          * @see write1DBarcode()
  9828.          */
  9829.         public function writeBarcode($x$y$w$h$type$style$font$xres$code{
  9830.             // convert old settings for the new write1DBarcode() function.
  9831.             $xres $xres;
  9832.             $newstyle array(
  9833.                 'position' => 'L',
  9834.                 'border' => false,
  9835.                 'padding' => 0,
  9836.                 'fgcolor' => array(0,0,0),
  9837.                 'bgcolor' => false,
  9838.                 'text' => true,
  9839.                 'font' => $font,
  9840.                 'fontsize' => 8,
  9841.                 'stretchtext' => 4
  9842.             );
  9843.             if ($style 1{
  9844.                 $newstyle['border'true;
  9845.             }
  9846.             if ($style 2{
  9847.                 $newstyle['bgcolor'false;
  9848.             }
  9849.             if ($style 4{
  9850.                 $newstyle['position''C';
  9851.             elseif ($style 8{
  9852.                 $newstyle['position''L';
  9853.             elseif ($style 16{
  9854.                 $newstyle['position''R';
  9855.             }
  9856.             if ($style 128{
  9857.                 $newstyle['text'true;
  9858.             }
  9859.             if ($style 256{
  9860.                 $newstyle['stretchtext'4;
  9861.             }
  9862.             $this->write1DBarcode($code$type$x$y$w$h$xres$newstyle'');
  9863.         }
  9864.         
  9865.         /**
  9866.          * Returns an array containing current margins:
  9867.          * <ul>
  9868.                 <li>$ret['left'] = left  margin</li>
  9869.                 <li>$ret['right'] = right margin</li>
  9870.                 <li>$ret['top'] = top margin</li>
  9871.                 <li>$ret['bottom'] = bottom margin</li>
  9872.                 <li>$ret['header'] = header margin</li>
  9873.                 <li>$ret['footer'] = footer margin</li>
  9874.                 <li>$ret['cell'] = cell margin</li>
  9875.          * </ul>
  9876.          * @return array containing all margins measures
  9877.          * @since 3.2.000 (2008-06-23)
  9878.          */
  9879.         public function getMargins({
  9880.             $ret array(
  9881.                 'left' => $this->lMargin,
  9882.                 'right' => $this->rMargin,
  9883.                 'top' => $this->tMargin,
  9884.                 'bottom' => $this->bMargin,
  9885.                 'header' => $this->header_margin,
  9886.                 'footer' => $this->footer_margin,
  9887.                 'cell' => $this->cMargin,
  9888.             );
  9889.             return $ret;
  9890.         }
  9891.         
  9892.         /**
  9893.          * Returns an array containing original margins:
  9894.          * <ul>
  9895.                 <li>$ret['left'] = left  margin</li>
  9896.                 <li>$ret['right'] = right margin</li>
  9897.          * </ul>
  9898.          * @return array containing all margins measures
  9899.          * @since 4.0.012 (2008-07-24)
  9900.          */
  9901.         public function getOriginalMargins({
  9902.             $ret array(
  9903.                 'left' => $this->original_lMargin,
  9904.                 'right' => $this->original_rMargin
  9905.             );
  9906.             return $ret;
  9907.         }
  9908.         
  9909.         /**
  9910.          * Returns the current font size.
  9911.          * @return current font size
  9912.          * @access public
  9913.          * @since 3.2.000 (2008-06-23)
  9914.          */
  9915.         public function getFontSize({
  9916.             return $this->FontSize;
  9917.         }
  9918.         
  9919.         /**
  9920.          * Returns the current font size in points unit.
  9921.          * @return current font size in points unit
  9922.          * @access public
  9923.          * @since 3.2.000 (2008-06-23)
  9924.          */
  9925.         public function getFontSizePt({
  9926.             return $this->FontSizePt;
  9927.         }
  9928.         
  9929.         /**
  9930.          * Returns the current font family name.
  9931.          * @return string current font family name
  9932.          * @access public
  9933.          * @since 4.3.008 (2008-12-05)
  9934.          */
  9935.         public function getFontFamily({
  9936.             return $this->FontFamily;
  9937.         }
  9938.         
  9939.         /**
  9940.          * Returns the current font style.
  9941.          * @return string current font style
  9942.          * @access public
  9943.          * @since 4.3.008 (2008-12-05)
  9944.          */
  9945.         public function getFontStyle({
  9946.             return $this->FontStyle;
  9947.         }
  9948.         
  9949.         /**
  9950.          * Prints a cell (rectangular area) with optional borders, background color and html text string.
  9951.          * The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.<br />
  9952.          * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  9953.          * @param float $w Cell width. If 0, the cell extends up to the right margin.
  9954.          * @param float $h Cell minimum height. The cell extends automatically if needed.
  9955.          * @param float $x upper-left corner X coordinate
  9956.          * @param float $y upper-left corner Y coordinate
  9957.          * @param string $html html text to print. Default value: empty string.
  9958.          * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  9959.          * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL language)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  9960.     Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  9961.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  9962.          * @param boolean $reseth if true reset the last cell height (default true).
  9963.          * @param string $align Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  9964.          * @uses MultiCell()
  9965.          * @see Multicell(), writeHTML()
  9966.          */
  9967.         public function writeHTMLCell($w$h$x$y$html=''$border=0$ln=0$fill=0$reseth=true$align=''{
  9968.             return $this->MultiCell($w$h$html$border$align$fill$ln$x$y$reseth0true);
  9969.         }
  9970.         
  9971.         /**
  9972.           * Returns the HTML DOM array.
  9973.           * <ul><li>$dom[$key]['tag'] = true if tag, false otherwise;</li><li>$dom[$key]['value'] = tag name or text;</li><li>$dom[$key]['opening'] = true if opening tag, false otherwise;</li><li>$dom[$key]['attribute'] = array of attributes (attribute name is the key);</li><li>$dom[$key]['style'] = array of style attributes (attribute name is the key);</li><li>$dom[$key]['parent'] = id of parent element;</li><li>$dom[$key]['fontname'] = font family name;</li><li>$dom[$key]['fontstyle'] = font style;</li><li>$dom[$key]['fontsize'] = font size in points;</li><li>$dom[$key]['bgcolor'] = RGB array of background color;</li><li>$dom[$key]['fgcolor'] = RGB array of foreground color;</li><li>$dom[$key]['width'] = width in pixels;</li><li>$dom[$key]['height'] = height in pixels;</li><li>$dom[$key]['align'] = text alignment;</li><li>$dom[$key]['cols'] = number of colums in table;</li><li>$dom[$key]['rows'] = number of rows in table;</li></ul>
  9974.          * @param string $html html code
  9975.          * @return array 
  9976.          * @since 3.2.000 (2008-06-20)
  9977.          */
  9978.         protected function getHtmlDomArray($html{
  9979.             // remove all unsupported tags (the line below lists all supported tags)
  9980.             $html strip_tags($html'<marker/><a><b><blockquote><br><br/><dd><del><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><li><ol><p><pre><small><span><strong><sub><sup><table><td><th><tr><tt><u><ul>')
  9981.             //replace some blank characters
  9982.             $html preg_replace('@(\r\n|\r)@'"\n"$html);
  9983.             $repTable array("\t" => ' '"\0" => ' '"\x0B" => ' '"\\" => "\\\\");
  9984.             $html strtr($html$repTable);
  9985.             while (preg_match("'<pre([^\>]*)>(.*?)\n(.*?)</pre>'si"$html)) {
  9986.                 // preserve newlines on <pre> tag
  9987.                 $html preg_replace("'<pre([^\>]*)>(.*?)\n(.*?)</pre>'si""<pre\\1>\\2<br />\\3</pre>"$html);
  9988.             }
  9989.             $html str_replace("\n"' '$html);
  9990.             /*
  9991.             $html = preg_replace("'<div([^\>]*)>'si", "<br /><table><tr><td\\1>", $html);
  9992.             $html = preg_replace("'</div>'si", "</td></tr></table>", $html);
  9993.             $html = preg_replace("'<pre([^\>]*)>'si", "<table><tr><td\\1>", $html);
  9994.             $html = preg_replace("'</pre>'si", "</td></tr></table>", $html);
  9995.             */
  9996.             // remove extra spaces from tables
  9997.             $html preg_replace('/[\s]*<\/table>[\s]*/''</table>'$html);
  9998.             $html preg_replace('/[\s]*<\/tr>[\s]*/''</tr>'$html);
  9999.             $html preg_replace('/[\s]*<tr/''<tr'$html);
  10000.             $html preg_replace('/[\s]*<\/th>[\s]*/''</th>'$html);
  10001.             $html preg_replace('/[\s]*<th/''<th'$html);
  10002.             $html preg_replace('/[\s]*<\/td>[\s]*/''</td>'$html);
  10003.             $html preg_replace('/[\s]*<td/''<td'$html);
  10004.             $html preg_replace('/<\/th>/''<marker/></th>'$html);
  10005.             $html preg_replace('/<\/td>/''<marker/></td>'$html);
  10006.             $html preg_replace('/<\/table><marker\/>/''</table>'$html);
  10007.             $html preg_replace('/<img/'' <img'$html);
  10008.             $html preg_replace('/<img([^\>]*)>/xi''<img\\1><span></span>'$html);
  10009.             $html preg_replace('/[\s]*<li/''<li'$html);
  10010.             $html preg_replace('/<\/li>[\s]*/''</li>'$html);            
  10011.             // pattern for generic tag
  10012.             $tagpattern '/(<[^>]+>)/';
  10013.             // explodes the string
  10014.             $a preg_split($tagpattern$html-1PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_NO_EMPTY);
  10015.             // count elements
  10016.             $maxel count($a);
  10017.             $key 0;
  10018.             // create an array of elements
  10019.             $dom array();
  10020.             $dom[$keyarray();
  10021.             // set first void element
  10022.             $dom[$key]['tag'false;
  10023.             $dom[$key]['value''';
  10024.             $dom[$key]['parent'0;
  10025.             $dom[$key]['fontname'$this->FontFamily;
  10026.             $dom[$key]['fontstyle'$this->FontStyle;
  10027.             $dom[$key]['fontsize'$this->FontSizePt;
  10028.             $dom[$key]['bgcolor'false;
  10029.             $dom[$key]['fgcolor'$this->fgcolor;
  10030.             $dom[$key]['align''';
  10031.             $dom[$key]['listtype''';
  10032.             ++$key;
  10033.             $level array();
  10034.             array_push($level0)// root
  10035.             while ($key <= $maxel{
  10036.                 if ($key 0{
  10037.                     $dom[$keyarray();
  10038.                 }
  10039.                 $element $a[($key-1)];
  10040.                 if (preg_match($tagpattern$element)) {
  10041.                     // html tag
  10042.                     $dom[$key]['tag'true;
  10043.                     $element substr($element1-1);
  10044.                     // get tag name
  10045.                     preg_match('/[\/]?([a-zA-Z0-9]*)/'$element$tag);
  10046.                     $dom[$key]['value'strtolower($tag[1]);
  10047.                     if ($element{0== '/'{
  10048.                         // closing html tag
  10049.                         $dom[$key]['opening'false;
  10050.                         $dom[$key]['parent'end($level);
  10051.                         array_pop($level);
  10052.                         $dom[$key]['fontname'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  10053.                         $dom[$key]['fontstyle'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  10054.                         $dom[$key]['fontsize'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  10055.                         $dom[$key]['bgcolor'$dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  10056.                         $dom[$key]['fgcolor'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  10057.                         $dom[$key]['align'$dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  10058.                         if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  10059.                             $dom[$key]['listtype'$dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  10060.                         }
  10061.                         // set the number of columns in table tag
  10062.                         if (($dom[$key]['value'== 'tr'AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  10063.                             $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'$dom[($dom[$key]['parent'])]['cols'];
  10064.                         }
  10065.                         if (($dom[$key]['value'== 'td'OR ($dom[$key]['value'== 'th')) {
  10066.                             $dom[($dom[$key]['parent'])]['content''';
  10067.                             for ($i ($dom[$key]['parent'1)$i $key++$i{
  10068.                                 $dom[($dom[$key]['parent'])]['content'.= $a[($i-1)];
  10069.                             }
  10070.                             $key $i;
  10071.                         }
  10072.                     else {
  10073.                         // opening html tag
  10074.                         $dom[$key]['opening'true;
  10075.                         $dom[$key]['parent'end($level);
  10076.                         if (substr($element-11!= '/'{
  10077.                             // not self-closing tag
  10078.                             array_push($level$key);
  10079.                             $dom[$key]['self'false;
  10080.                         else {
  10081.                             $dom[$key]['self'true;
  10082.                         }
  10083.                         // copy some values from parent
  10084.                         $parentkey 0;
  10085.                         if ($key 0{
  10086.                             $parentkey $dom[$key]['parent'];
  10087.                             $dom[$key]['fontname'$dom[$parentkey]['fontname'];
  10088.                             $dom[$key]['fontstyle'$dom[$parentkey]['fontstyle'];
  10089.                             $dom[$key]['fontsize'$dom[$parentkey]['fontsize'];
  10090.                             $dom[$key]['bgcolor'$dom[$parentkey]['bgcolor'];
  10091.                             $dom[$key]['fgcolor'$dom[$parentkey]['fgcolor'];
  10092.                             $dom[$key]['align'$dom[$parentkey]['align'];
  10093.                             $dom[$key]['listtype'$dom[$parentkey]['listtype'];
  10094.                         }
  10095.                         // get attributes
  10096.                         preg_match_all('/([^=\s]*)=["\']?([^"\']*)["\']?/'$element$attr_arrayPREG_PATTERN_ORDER);
  10097.                         $dom[$key]['attribute'array()// reset attribute array
  10098.                         while (list($id$nameeach($attr_array[1])) {
  10099.                             $dom[$key]['attribute'][strtolower($name)$attr_array[2][$id];
  10100.                         }
  10101.                         // split style attributes
  10102.                         if (isset($dom[$key]['attribute']['style'])) {
  10103.                             // get style attributes
  10104.                             preg_match_all('/([^;:\s]*):([^;]*)/'$dom[$key]['attribute']['style']$style_arrayPREG_PATTERN_ORDER);
  10105.                             $dom[$key]['style'array()// reset style attribute array
  10106.                             while (list($id$nameeach($style_array[1])) {
  10107.                                 $dom[$key]['style'][strtolower($name)trim($style_array[2][$id]);
  10108.                             }
  10109.                             // --- get some style attributes ---
  10110.                             if (isset($dom[$key]['style']['font-family'])) {
  10111.                                 // font family
  10112.                                 if (isset($dom[$key]['style']['font-family'])) {
  10113.                                     $fontslist split(','strtolower($dom[$key]['style']['font-family']));
  10114.                                     foreach ($fontslist as $font{
  10115.                                         $font trim(strtolower($font));
  10116.                                         if (in_array($font$this->fontlistOR in_array($font$this->fontkeys)) {
  10117.                                             $dom[$key]['fontname'$font;
  10118.                                             break;
  10119.                                         }
  10120.                                     }
  10121.                                 }
  10122.                             }
  10123.                             // list-style-type
  10124.                             if (isset($dom[$key]['style']['list-style-type'])) {
  10125.                                 $dom[$key]['listtype'trim(strtolower($dom[$key]['style']['list-style-type']));
  10126.                                 if ($dom[$key]['listtype'== 'inherit'{
  10127.                                     $dom[$key]['listtype'$dom[$parentkey]['listtype'];
  10128.                                 }
  10129.                             }
  10130.                             // font size
  10131.                             if (isset($dom[$key]['style']['font-size'])) {
  10132.                                 $fsize trim($dom[$key]['style']['font-size']);
  10133.                                 switch ($fsize{
  10134.                                     // absolute-size
  10135.                                     case 'xx-small'{
  10136.                                         $dom[$key]['fontsize'$dom[0]['fontsize'4;
  10137.                                         break;
  10138.                                     }
  10139.                                     case 'x-small'{
  10140.                                         $dom[$key]['fontsize'$dom[0]['fontsize'3;
  10141.                                         break;
  10142.                                     }
  10143.                                     case 'small'{
  10144.                                         $dom[$key]['fontsize'$dom[0]['fontsize'2;
  10145.                                         break;
  10146.                                     }
  10147.                                     case 'medium'{
  10148.                                         $dom[$key]['fontsize'$dom[0]['fontsize'];
  10149.                                         break;
  10150.                                     }
  10151.                                     case 'large'{
  10152.                                         $dom[$key]['fontsize'$dom[0]['fontsize'2;
  10153.                                         break;
  10154.                                     }
  10155.                                     case 'x-large'{
  10156.                                         $dom[$key]['fontsize'$dom[0]['fontsize'4;
  10157.                                         break;
  10158.                                     }
  10159.                                     case 'xx-large'{
  10160.                                         $dom[$key]['fontsize'$dom[0]['fontsize'6;
  10161.                                         break;
  10162.                                     }
  10163.                                     // relative-size
  10164.                                     case 'smaller'{
  10165.                                         $dom[$key]['fontsize'$dom[$parentkey]['fontsize'3;
  10166.                                         break;
  10167.                                     }
  10168.                                     case 'larger'{
  10169.                                         $dom[$key]['fontsize'$dom[$parentkey]['fontsize'3;
  10170.                                         break;
  10171.                                     }
  10172.                                     default{
  10173.                                         $dom[$key]['fontsize'$this->getHTMLUnitToUnits($fsize$dom[$parentkey]['fontsize']'pt'true);
  10174.                                     }
  10175.                                 }
  10176.                             }
  10177.                             // font style
  10178.                             if (isset($dom[$key]['style']['font-weight']AND (strtolower($dom[$key]['style']['font-weight']{0}== 'b')) {
  10179.                                 $dom[$key]['fontstyle'.= 'B';
  10180.                             }
  10181.                             if (isset($dom[$key]['style']['font-style']AND (strtolower($dom[$key]['style']['font-style']{0}== 'i')) {
  10182.                                 $dom[$key]['fontstyle'.= '"I';
  10183.                             }
  10184.                             // font color
  10185.                             if (isset($dom[$key]['style']['color']AND (!empty($dom[$key]['style']['color']))) {
  10186.                                 $dom[$key]['fgcolor'$this->convertHTMLColorToDec($dom[$key]['style']['color']);
  10187.                             }
  10188.                             // background color
  10189.                             if (isset($dom[$key]['style']['background-color']AND (!empty($dom[$key]['style']['background-color']))) {
  10190.                                 $dom[$key]['bgcolor'$this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
  10191.                             }
  10192.                             // text-decoration
  10193.                             if (isset($dom[$key]['style']['text-decoration'])) {
  10194.                                 $decors explode(' 'strtolower($dom[$key]['style']['text-decoration']));
  10195.                                 foreach ($decors as $dec{
  10196.                                     $dec trim($dec);
  10197.                                     if (!empty($dec)) {
  10198.                                         if ($dec{0== 'u'{
  10199.                                             $dom[$key]['fontstyle'.= 'U';
  10200.                                         elseif ($dec{0== 'l'{
  10201.                                             $dom[$key]['fontstyle'.= 'D';
  10202.                                         }
  10203.                                     }
  10204.                                 }
  10205.                             }
  10206.                             // check for width attribute
  10207.                             if (isset($dom[$key]['style']['width'])) {
  10208.                                 $dom[$key]['width'$dom[$key]['style']['width'];
  10209.                             }
  10210.                             // check for height attribute
  10211.                             if (isset($dom[$key]['style']['height'])) {
  10212.                                 $dom[$key]['height'$dom[$key]['style']['height'];
  10213.                             }
  10214.                             // check for text alignment
  10215.                             if (isset($dom[$key]['style']['text-align'])) {
  10216.                                 $dom[$key]['align'strtoupper($dom[$key]['style']['text-align']{0});
  10217.                             }
  10218.                             // check for border attribute
  10219.                             if (isset($dom[$key]['style']['border'])) {
  10220.                                 $dom[$key]['attribute']['border'$dom[$key]['style']['border'];
  10221.                             }
  10222.                         }
  10223.                         // check for font tag
  10224.                         if ($dom[$key]['value'== 'font'{
  10225.                             // font family
  10226.                             if (isset($dom[$key]['attribute']['face'])) {
  10227.                                 $fontslist split(','strtolower($dom[$key]['attribute']['face']));
  10228.                                 foreach ($fontslist as $font{
  10229.                                     $font trim(strtolower($font));
  10230.                                     if (in_array($font$this->fontlistOR in_array($font$this->fontkeys)) {
  10231.                                         $dom[$key]['fontname'$font;
  10232.                                         break;
  10233.                                     }
  10234.                                 }
  10235.                             }
  10236.                             // font size
  10237.                             if (isset($dom[$key]['attribute']['size'])) {
  10238.                                 if ($key 0{
  10239.                                     if ($dom[$key]['attribute']['size']{0== '+'{
  10240.                                         $dom[$key]['fontsize'$dom[($dom[$key]['parent'])]['fontsize'intval(substr($dom[$key]['attribute']['size']1));
  10241.                                     elseif ($dom[$key]['attribute']['size']{0== '-'{
  10242.                                         $dom[$key]['fontsize'$dom[($dom[$key]['parent'])]['fontsize'intval(substr($dom[$key]['attribute']['size']1));
  10243.                                     else {
  10244.                                         $dom[$key]['fontsize'intval($dom[$key]['attribute']['size']);
  10245.                                     }
  10246.                                 else {
  10247.                                     $dom[$key]['fontsize'intval($dom[$key]['attribute']['size']);
  10248.                                 }
  10249.                             }
  10250.                         }
  10251.                         if (($dom[$key]['value'== 'ul'OR ($dom[$key]['value'== 'ol'OR ($dom[$key]['value'== 'dl')) {
  10252.                             // force natural alignment for lists
  10253.                             if ($this->rtl{
  10254.                                 $dom[$key]['align''R';
  10255.                             else {
  10256.                                 $dom[$key]['align''L';
  10257.                             }
  10258.                         }
  10259.                         if (($dom[$key]['value'== 'small'OR ($dom[$key]['value'== 'sup'OR ($dom[$key]['value'== 'sub')) {
  10260.                             $dom[$key]['fontsize'$dom[$key]['fontsize'K_SMALL_RATIO;
  10261.                         }
  10262.                         if (($dom[$key]['value'== 'strong'OR ($dom[$key]['value'== 'b')) {
  10263.                             $dom[$key]['fontstyle'.= 'B';
  10264.                         }
  10265.                         if (($dom[$key]['value'== 'em'OR ($dom[$key]['value'== 'i')) {
  10266.                             $dom[$key]['fontstyle'.= 'I';
  10267.                         }
  10268.                         if ($dom[$key]['value'== 'u'{
  10269.                             $dom[$key]['fontstyle'.= 'U';
  10270.                         }
  10271.                         if ($dom[$key]['value'== 'del'{
  10272.                             $dom[$key]['fontstyle'.= 'D';
  10273.                         }
  10274.                         if (($dom[$key]['value'== 'pre'OR ($dom[$key]['value'== 'tt')) {
  10275.                             $dom[$key]['fontname''courier';
  10276.                         }
  10277.                         if (($dom[$key]['value']{0== 'h'AND (intval($dom[$key]['value']{1}0AND (intval($dom[$key]['value']{1}7)) {
  10278.                             $headsize (intval($dom[$key]['value']{1})) 2;
  10279.                             $dom[$key]['fontsize'$dom[0]['fontsize'$headsize;
  10280.                             $dom[$key]['fontstyle'.= 'B';
  10281.                         }
  10282.                         if (($dom[$key]['value'== 'table')) {
  10283.                             $dom[$key]['rows'0// number of rows
  10284.                             $dom[$key]['trids'array()// IDs of TR elements
  10285.                         }
  10286.                         if (($dom[$key]['value'== 'tr')) {
  10287.                             $dom[$key]['cols'0;
  10288.                             // store the number of rows on table element
  10289.                             ++$dom[($dom[$key]['parent'])]['rows'];
  10290.                             // store the TR elements IDs on table element
  10291.                             array_push($dom[($dom[$key]['parent'])]['trids']$key);
  10292.                         }
  10293.                         if (($dom[$key]['value'== 'th'OR ($dom[$key]['value'== 'td')) {
  10294.                             if (isset($dom[$key]['attribute']['colspan'])) {
  10295.                                 $colspan intval($dom[$key]['attribute']['colspan']);
  10296.                             else {
  10297.                                 $colspan 1;
  10298.                             }
  10299.                             $dom[$key]['attribute']['colspan'$colspan;
  10300.                             $dom[($dom[$key]['parent'])]['cols'+= $colspan;
  10301.                         }
  10302.                         // set foreground color attribute
  10303.                         if (isset($dom[$key]['attribute']['color']AND (!empty($dom[$key]['attribute']['color']))) {
  10304.                             $dom[$key]['fgcolor'$this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
  10305.                         }
  10306.                         // set background color attribute
  10307.                         if (isset($dom[$key]['attribute']['bgcolor']AND (!empty($dom[$key]['attribute']['bgcolor']))) {
  10308.                             $dom[$key]['bgcolor'$this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
  10309.                         }
  10310.                         // check for width attribute
  10311.                         if (isset($dom[$key]['attribute']['width'])) {
  10312.                             $dom[$key]['width'$dom[$key]['attribute']['width'];
  10313.                         }
  10314.                         // check for height attribute
  10315.                         if (isset($dom[$key]['attribute']['height'])) {
  10316.                             $dom[$key]['height'$dom[$key]['attribute']['height'];
  10317.                         }
  10318.                         // check for text alignment
  10319.                         if (isset($dom[$key]['attribute']['align']AND (!empty($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'!== 'img')) {
  10320.                             $dom[$key]['align'strtoupper($dom[$key]['attribute']['align']{0});
  10321.                         }
  10322.                     // end opening tag
  10323.                 else {
  10324.                     // text
  10325.                     $dom[$key]['tag'false;
  10326.                     $dom[$key]['value'stripslashes($this->unhtmlentities($element));
  10327.                     $dom[$key]['parent'end($level);
  10328.                 }
  10329.                 ++$key;
  10330.             }
  10331.             return $dom;
  10332.         }
  10333.         
  10334.         /**
  10335.          * Allows to preserve some HTML formatting (limited support).<br />
  10336.          * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  10337.          * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, small, span, strong, sub, sup, table, td, th, tr, u, ul,
  10338.          * @param string $html text to display
  10339.          * @param boolean $ln if true add a new line after text (default = true)
  10340.          * @param int $fill Indicates if the background must be painted (true) or transparent (false).
  10341.          * @param boolean $reseth if true reset the last cell height (default false).
  10342.          * @param boolean $cell if true add the default cMargin space to each Write (default false).
  10343.          * @param string $align Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  10344.          */
  10345.         public function writeHTML($html$ln=true$fill=false$reseth=false$cell=false$align=''{
  10346.             $gvars $this->getGraphicVars();
  10347.             // store current values
  10348.             $prevPage $this->page;
  10349.             $prevlMargin $this->lMargin;
  10350.             $prevrMargin $this->rMargin;
  10351.             $curfontname $this->FontFamily;
  10352.             $curfontstyle $this->FontStyle;
  10353.             $curfontsize $this->FontSizePt;            
  10354.             $this->newline true;
  10355.             $minstartliney $this->y;
  10356.             $yshift 0;
  10357.             $startlinepage $this->page;
  10358.             $newline true;
  10359.             $loop 0;
  10360.             $curpos 0;
  10361.             $blocktags array('blockquote','br','dd','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','ul');
  10362.             $this->premode false;
  10363.             if (isset($this->PageAnnots[$this->page])) {
  10364.                 $pask count($this->PageAnnots[$this->page]);
  10365.             else {
  10366.                 $pask 0;
  10367.             }
  10368.             if (isset($this->footerlen[$this->page])) {
  10369.                 $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  10370.             else {
  10371.                 $this->footerpos[$this->page$this->pagelen[$this->page];
  10372.             }
  10373.             $startlinepos $this->footerpos[$this->page];
  10374.             $lalign $align;
  10375.             $plalign $align;
  10376.             if ($this->rtl{
  10377.                 $w $this->x $this->lMargin;
  10378.             else {
  10379.                 $w $this->w $this->rMargin $this->x;
  10380.             }
  10381.             $w -= ($this->cMargin);
  10382.             if ($cell{
  10383.                 if ($this->rtl{
  10384.                     $this->x -= $this->cMargin;
  10385.                 else {
  10386.                     $this->x += $this->cMargin;
  10387.                 }
  10388.             }
  10389.             if ($this->customlistindent >= 0{
  10390.                 $this->listindent $this->customlistindent;
  10391.             else {
  10392.                 $this->listindent $this->GetStringWidth('0000');
  10393.             }
  10394.             $this->listnum 0;
  10395.             if ((empty($this->lasth))OR ($reseth)) {
  10396.                 //set row height
  10397.                 $this->lasth $this->FontSize $this->cell_height_ratio
  10398.             }
  10399.             $dom $this->getHtmlDomArray($html);
  10400.             $maxel count($dom);
  10401.             $key 0;
  10402.             while ($key $maxel{
  10403.                 if ($dom[$key]['tag'OR ($key == 0)) {
  10404.                     if ((($dom[$key]['value'== 'table'OR ($dom[$key]['value'== 'tr')) AND (isset($dom[$key]['align']))) {
  10405.                         $dom[$key]['align'($this->rtl'R' 'L';
  10406.                     }
  10407.                     // vertically align image in line
  10408.                     if ((!$this->newline
  10409.                         AND ($dom[$key]['value'== 'img'
  10410.                         AND (isset($dom[$key]['attribute']['height']))
  10411.                         AND ($dom[$key]['attribute']['height'0)
  10412.                         AND (!((($this->y $this->getHTMLUnitToUnits($dom[$key]['attribute']['height']$this->lasth'px')) $this->PageBreakTrigger
  10413.                             AND (!$this->InFooter
  10414.                             AND $this->AcceptPageBreak()))
  10415.                         {
  10416.                         if ($this->page $startlinepage{
  10417.                             // fix lines splitted over two pages
  10418.                             if (isset($this->footerlen[$startlinepage])) {
  10419.                                 $curpos $this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  10420.                             }
  10421.                             // line to be moved one page forward
  10422.                             $linebeg substr($this->getPageBuffer($startlinepage)$startlinepos($curpos $startlinepos));
  10423.                             $tstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  10424.                             $tend substr($this->getPageBuffer($startlinepage)$curpos);
  10425.                             // remove line start from previous page
  10426.                             $this->setPageBuffer($startlinepage$tstart.''.$tend);
  10427.                             $tstart substr($this->getPageBuffer($this->page)0$this->intmrk[$this->page]);
  10428.                             $tend substr($this->getPageBuffer($this->page)$this->intmrk[$this->page]);
  10429.                             // add line start to current page
  10430.                             $yshift $minstartliney $this->y;
  10431.                             $try sprintf('1 0 0 1 0 %.3f cm'($yshift $this->k));
  10432.                             $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  10433.                             // shift the annotations and links
  10434.                             if (isset($this->PageAnnots[$startlinepage])) {
  10435.                                 foreach ($this->PageAnnots[$startlinepageas $pak => $pac{
  10436.                                     if ($pak >= $pask{
  10437.                                         $this->PageAnnots[$this->page][$pac;
  10438.                                         unset($this->PageAnnots[$startlinepage][$pak]);
  10439.                                         $npak count($this->PageAnnots[$this->page]1;
  10440.                                         $this->PageAnnots[$this->page][$npak]['y'-= $yshift;
  10441.                                     }
  10442.                                 }
  10443.                             }
  10444.                         }
  10445.                         $this->y += (($curfontsize $this->k$this->getHTMLUnitToUnits($dom[$key]['attribute']['height']$this->lasth'px'));
  10446.                         $minstartliney min($this->y$minstartliney);
  10447.                     elseif (isset($dom[$key]['fontname']OR isset($dom[$key]['fontstyle']OR isset($dom[$key]['fontsize'])) {
  10448.                         // account for different font size
  10449.                         $pfontname $curfontname;
  10450.                         $pfontstyle $curfontstyle;
  10451.                         $pfontsize $curfontsize;
  10452.                         $fontname = isset($dom[$key]['fontname']$dom[$key]['fontname'$curfontname;
  10453.                         $fontstyle = isset($dom[$key]['fontstyle']$dom[$key]['fontstyle'$curfontstyle;
  10454.                         $fontsize = isset($dom[$key]['fontsize']$dom[$key]['fontsize'$curfontsize;
  10455.                         if (($fontname != $curfontnameOR ($fontstyle != $curfontstyleOR ($fontsize != $curfontsize)) {
  10456.                             $this->SetFont($fontname$fontstyle$fontsize);
  10457.                             $this->lasth $this->FontSize $this->cell_height_ratio;
  10458.                             if (is_numeric($fontsizeAND ($fontsize 0
  10459.                                 AND is_numeric($curfontsizeAND ($curfontsize 0
  10460.                                 AND ($fontsize != $curfontsizeAND (!$this->newline
  10461.                                 AND ($key ($maxel 1))
  10462.                                 {
  10463.                                 if ((!$this->newlineAND ($this->page $startlinepage)) {
  10464.                                     // fix lines splitted over two pages
  10465.                                     if (isset($this->footerlen[$startlinepage])) {
  10466.                                         $curpos $this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  10467.                                     }
  10468.                                     // line to be moved one page forward
  10469.                                     $linebeg substr($this->getPageBuffer($startlinepage)$startlinepos($curpos $startlinepos));
  10470.                                     $tstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  10471.                                     $tend substr($this->getPageBuffer($startlinepage)$curpos);
  10472.                                     // remove line start from previous page
  10473.                                     $this->setPageBuffer($startlinepage$tstart.''.$tend);
  10474.                                     $tstart substr($this->getPageBuffer($this->page)0$this->intmrk[$this->page]);
  10475.                                     $tend substr($this->getPageBuffer($this->page)$this->intmrk[$this->page]);
  10476.                                     // add line start to current page
  10477.                                     $yshift $minstartliney $this->y;
  10478.                                     $try sprintf('1 0 0 1 0 %.3f cm'($yshift $this->k));
  10479.                                     $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  10480.                                     // shift the annotations and links
  10481.                                     if (isset($this->PageAnnots[$startlinepage])) {
  10482.                                         foreach ($this->PageAnnots[$startlinepageas $pak => $pac{
  10483.                                             if ($pak >= $pask{
  10484.                                                 $this->PageAnnots[$this->page][$pac;
  10485.                                                 unset($this->PageAnnots[$startlinepage][$pak]);
  10486.                                                 $npak count($this->PageAnnots[$this->page]1;
  10487.                                                 $this->PageAnnots[$this->page][$npak]['y'-= $yshift;
  10488.                                             }
  10489.                                         }
  10490.                                     }
  10491.                                 }
  10492.                                 $this->y += (($curfontsize $fontsize$this->k);
  10493.                                 $minstartliney min($this->y$minstartliney);
  10494.                             }
  10495.                             $curfontname $fontname;
  10496.                             $curfontstyle $fontstyle;
  10497.                             $curfontsize $fontsize;
  10498.                         }
  10499.                     }
  10500.                     if (($plalign == 'J'AND (in_array($dom[$key]['value']$blocktags))) {
  10501.                         $plalign '';
  10502.                     }
  10503.                     // get current position on page buffer
  10504.                     $curpos $this->pagelen[$startlinepage];
  10505.                     if (isset($dom[$key]['bgcolor']AND ($dom[$key]['bgcolor'!== false)) {
  10506.                         $this->SetFillColorArray($dom[$key]['bgcolor']);
  10507.                         $wfill true;
  10508.                     else {
  10509.                         $wfill $fill false;
  10510.                     }
  10511.                     if (isset($dom[$key]['fgcolor']AND ($dom[$key]['fgcolor'!== false)) {
  10512.                         $this->SetTextColorArray($dom[$key]['fgcolor']);
  10513.                     }
  10514.                     if (isset($dom[$key]['align'])) {
  10515.                         $lalign $dom[$key]['align'];
  10516.                     }
  10517.                     if (empty($lalign)) {
  10518.                         $lalign $align;
  10519.                     }
  10520.                 }
  10521.                 // align lines
  10522.                 if ($this->newline AND (strlen($dom[$key]['value']0AND ($dom[$key]['value'!= 'td'AND ($dom[$key]['value'!= 'th')) {
  10523.                     $newline true;
  10524.                     // we are at the beginning of a new line
  10525.                     if (isset($startlinex)) {
  10526.                         $yshift $minstartliney $startliney;
  10527.                         if (($yshift 0OR ($this->page $startlinepage)) {
  10528.                             $yshift 0;
  10529.                         }
  10530.                         if ((isset($plalignAND ((($plalign == 'C'OR ($plalign == 'J'OR (($plalign == 'R'AND (!$this->rtl)) OR (($plalign == 'L'AND ($this->rtl))))) OR ($yshift 0)) {
  10531.                             // the last line must be shifted to be aligned as requested
  10532.                             $linew abs($this->endlinex $startlinex);
  10533.                             $pstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  10534.                             if (isset($opentagposAND isset($this->footerlen[$startlinepage])) {
  10535.                                 $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  10536.                                 $midpos min($opentagpos$this->footerpos[$startlinepage]);
  10537.                             elseif (isset($opentagpos)) {
  10538.                                 $midpos $opentagpos;
  10539.                             elseif (isset($this->footerlen[$startlinepage])) {
  10540.                                 $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  10541.                                 $midpos $this->footerpos[$startlinepage];
  10542.                             else {
  10543.                                 $midpos 0;
  10544.                             }
  10545.                             if ($midpos 0{
  10546.                                 $pmid substr($this->getPageBuffer($startlinepage)$startlinepos($midpos $startlinepos));
  10547.                                 $pend substr($this->getPageBuffer($startlinepage)$midpos);
  10548.                             else {
  10549.                                 $pmid substr($this->getPageBuffer($startlinepage)$startlinepos);
  10550.                                 $pend '';
  10551.                             }
  10552.                             // calculate shifting amount
  10553.                             $tw $w;
  10554.                             if ($this->lMargin != $prevlMargin{
  10555.                                 $tw += ($prevlMargin $this->lMargin);
  10556.                             }
  10557.                             if ($this->rMargin != $prevrMargin{
  10558.                                 $tw += ($prevrMargin $this->rMargin);
  10559.                             }
  10560.                             $mdiff abs($tw $linew);
  10561.                             $t_x 0;
  10562.                             if ($plalign == 'C'{
  10563.                                 if ($this->rtl{
  10564.                                     $t_x = -($mdiff 2);
  10565.                                 else {
  10566.                                     $t_x ($mdiff 2);
  10567.                                 }
  10568.                             elseif (($plalign == 'R'AND (!$this->rtl)) {
  10569.                                 // right alignment on LTR document
  10570.                                 $t_x $mdiff;    
  10571.                             elseif (($plalign == 'L'AND ($this->rtl)) {
  10572.                                 // left alignment on RTL document
  10573.                                 $t_x = -$mdiff;
  10574.                             elseif (($plalign == 'J'AND ($plalign == $lalign)){
  10575.                                 // Justification
  10576.                                 if ($this->rtl OR $this->tmprtl{
  10577.                                     $t_x $this->lMargin $this->endlinex;
  10578.                                 }
  10579.                                 $no 0;
  10580.                                 $ns 0;
  10581.                                 
  10582.                                 $pmidtemp $pmid;
  10583.                                 // escape special characters
  10584.                                 $pmidtemp preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmidtemp);
  10585.                                 $pmidtemp preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmidtemp);
  10586.                                 // search spaces
  10587.                                 if (preg_match_all('/\[\(([^\)]*)\)\]/x'$pmidtemp$lnstringPREG_PATTERN_ORDER)) {
  10588.                                     $maxkk count($lnstring[1]1;
  10589.                                     //foreach ($lnstring[1] as $kk => $value) {
  10590.                                     for ($kk=0$kk <= $maxkk++$kk{
  10591.                                         // restore special characters
  10592.                                         $lnstring[1][$kkstr_replace('#!#OP#!#''('$lnstring[1][$kk]);
  10593.                                         $lnstring[1][$kkstr_replace('#!#CP#!#'')'$lnstring[1][$kk]);
  10594.                                         if ($kk == $maxkk{
  10595.                                             if ($this->rtl OR $this->tmprtl{
  10596.                                                 $tvalue ltrim($lnstring[1][$kk]);
  10597.                                             else {
  10598.                                                 $tvalue rtrim($lnstring[1][$kk]);
  10599.                                             }
  10600.                                         else {
  10601.                                             $tvalue $lnstring[1][$kk];
  10602.                                         }
  10603.                                         // count spaces on line
  10604.                                         $no += substr_count($lnstring[1][$kk]chr(32));
  10605.                                         $ns += substr_count($tvaluechr(32));
  10606.                                     }
  10607.                                     if ($this->rtl OR $this->tmprtl{
  10608.                                         $t_x $this->lMargin $this->endlinex (($no $ns 1$this->GetStringWidth(chr(32)));
  10609.                                     }
  10610.                                     // calculate additional space to add to each space
  10611.                                     $spacewidth (($tw $linew (($no $ns$this->GetStringWidth(chr(32)))) ($ns?$ns:1)) $this->k;
  10612.                                     $spacewidthu ($tw $linew ($no $this->GetStringWidth(chr(32)))) ($ns?$ns:1$this->FontSize $this->k;
  10613.                                     $nsmax $ns;
  10614.                                     $ns 0;
  10615.                                     reset($lnstring);
  10616.                                     $offset 0;
  10617.                                     $strcount 0;
  10618.                                     $prev_epsposbeg 0;
  10619.                                     global $spacew;
  10620.                                     while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x'$pmid$strpiecePREG_OFFSET_CAPTURE$offset== 1{
  10621.                                         if ($this->rtl OR $this->tmprtl{
  10622.                                             $spacew ($spacewidth ($nsmax $ns));
  10623.                                         else {
  10624.                                             $spacew ($spacewidth $ns);
  10625.                                         }
  10626.                                         $offset $strpiece[2][1strlen($strpiece[2][0]);
  10627.                                         $epsposbeg strpos($pmid'q'.$this->epsmarker$offset);
  10628.                                         $epsposend strpos($pmid$this->epsmarker.'Q'$offsetstrlen($this->epsmarker.'Q');
  10629.                                         if ((($epsposbeg 0AND ($epsposend 0AND ($offset $epsposbegAND ($offset $epsposend)) 
  10630.                                             OR (($epsposbeg === falseAND ($epsposend 0AND ($offset $epsposend))) {
  10631.                                             // shift EPS images
  10632.                                             $trx sprintf('1 0 0 1 %.3f 0 cm'$spacew);
  10633.                                             $epsposbeg strpos($pmid'q'.$this->epsmarker($prev_epsposbeg 6));
  10634.                                             $pmid_b substr($pmid0$epsposbeg);
  10635.                                             $pmid_m substr($pmid$epsposbeg($epsposend $epsposbeg));
  10636.                                             $pmid_e substr($pmid$epsposend);
  10637.                                             $pmid $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  10638.                                             $offset $epsposend;
  10639.                                             continue;
  10640.                                         }
  10641.                                         $prev_epsposbeg $epsposbeg;
  10642.                                         $currentxpos 0;
  10643.                                         // shift blocks of code
  10644.                                         switch ($strpiece[2][0]{
  10645.                                             case 'Td':
  10646.                                             case 'cm':
  10647.                                             case 'm':
  10648.                                             case 'l'{
  10649.                                                 // get current X position
  10650.                                                 preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  10651.                                                 $currentxpos $xmatches[1];
  10652.                                                 if (($strcount <= $maxkkAND ($strpiece[2][0== 'Td')) {
  10653.                                                     if ($strcount == $maxkk{
  10654.                                                         if ($this->rtl OR $this->tmprtl{
  10655.                                                             $tvalue $lnstring[1][$strcount];
  10656.                                                         else {
  10657.                                                             $tvalue rtrim($lnstring[1][$strcount]);
  10658.                                                         }
  10659.                                                     else {
  10660.                                                         $tvalue $lnstring[1][$strcount];
  10661.                                                     }
  10662.                                                     $ns += substr_count($tvaluechr(32));
  10663.                                                     ++$strcount;
  10664.                                                 }
  10665.                                                 if ($this->rtl OR $this->tmprtl{
  10666.                                                     $spacew ($spacewidth ($nsmax $ns));
  10667.                                                 }
  10668.                                                 // justify block
  10669.                                                 $pmid preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'
  10670.                                                     create_function('$matches''global $spacew; 
  10671.                                                     $newx = sprintf("%.2f",(floatval($matches[1]) + $spacew));
  10672.                                                     return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];')$pmid1);
  10673.                                                 break;
  10674.                                             }
  10675.                                             case 're'{
  10676.                                                 // get current X position
  10677.                                                 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  10678.                                                 $currentxpos $xmatches[1];
  10679.                                                 // justify block
  10680.                                                 $pmid preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'
  10681.                                                     create_function('$matches''global $spacew; 
  10682.                                                     $newx = sprintf("%.2f",(floatval($matches[1]) + $spacew));
  10683.                                                     return "".$newx." ".$matches[2]." ".$matches[3]." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];')$pmid1);
  10684.                                                 break;
  10685.                                             }
  10686.                                             case 'c'{
  10687.                                                 // get current X position
  10688.                                                 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  10689.                                                 $currentxpos $xmatches[1];
  10690.                                                 // justify block
  10691.                                                 $pmid preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'
  10692.                                                     create_function('$matches''global $spacew; 
  10693.                                                     $newx1 = sprintf("%.3f",(floatval($matches[1]) + $spacew));
  10694.                                                     $newx2 = sprintf("%.3f",(floatval($matches[3]) + $spacew));
  10695.                                                     $newx3 = sprintf("%.3f",(floatval($matches[5]) + $spacew));
  10696.                                                     return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];')$pmid1);
  10697.                                                 break;
  10698.                                             }
  10699.                                         }
  10700.                                         // shift the annotations and links
  10701.                                         if (isset($this->PageAnnots[$this->page])) {
  10702.                                             foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  10703.                                                 if (($pac['y'>= $minstartlineyAND (($pac['x'$this->k>= ($currentxpos $this->feps)) AND (($pac['x'$this->k<= ($currentxpos $this->feps))) {
  10704.                                                     $this->PageAnnots[$this->page][$pak]['x'+= ($spacew $this->k);
  10705.                                                     $this->PageAnnots[$this->page][$pak]['w'+= (($spacewidth $pac['numspaces']$this->k);
  10706.                                                     break;
  10707.                                                 }
  10708.                                             }
  10709.                                         }
  10710.                                     // end of while
  10711.                                     // remove markers
  10712.                                     $pmid str_replace('x*#!#*x'''$pmid);
  10713.                                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  10714.                                         // multibyte characters
  10715.                                         $spacew $spacewidthu;
  10716.                                         $pmidtemp $pmid;
  10717.                                         // escape special characters
  10718.                                         $pmidtemp preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmidtemp);
  10719.                                         $pmidtemp preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmidtemp);
  10720.                                         $pmid preg_replace_callback("/\[\(([^\)]*)\)\]/x"
  10721.                                                     create_function('$matches''global $spacew;
  10722.                                                     $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
  10723.                                                     $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
  10724.                                                     return "[(".str_replace(chr(0).chr(32), ") ".(-2830 * $spacew)." (", $matches[1]).")]";')$pmidtemp);
  10725.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\n".$pend);
  10726.                                         $endlinepos strlen($pstart."\n".$pmid."\n");
  10727.                                     else {
  10728.                                         // non-unicode (single-byte characters)
  10729.                                         $rs sprintf("%.3f Tw"$spacewidth);
  10730.                                         $pmid preg_replace("/\[\(/x"$rs.' [('$pmid);
  10731.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  10732.                                         $endlinepos strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  10733.                                     }
  10734.                                 }
  10735.                             // end of J
  10736.                             if (($t_x != 0OR ($yshift 0)) {
  10737.                                 // shift the line
  10738.                                 $trx sprintf('1 0 0 1 %.3f %.3f cm'($t_x $this->k)($yshift $this->k));
  10739.                                 $this->setPageBuffer($startlinepage$pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend);
  10740.                                 $endlinepos strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n");
  10741.                                 // shift the annotations and links
  10742.                                 if (isset($this->PageAnnots[$this->page])) {
  10743.                                     foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  10744.                                         if ($pak >= $pask{
  10745.                                             $this->PageAnnots[$this->page][$pak]['x'+= $t_x;
  10746.                                             $this->PageAnnots[$this->page][$pak]['y'-= $yshift;
  10747.                                         }
  10748.                                     }
  10749.                                 }
  10750.                                 $this->y -= $yshift;
  10751.                             }
  10752.                         }
  10753.                     }
  10754.                     $this->newline false;
  10755.                     $pbrk $this->checkPageBreak($this->lasth);
  10756.                     $this->SetFont($fontname$fontstyle$fontsize);
  10757.                     if ($wfill{
  10758.                         $this->SetFillColorArray($this->bgcolor);
  10759.                     }
  10760.                     $startlinex $this->x;
  10761.                     $startliney $this->y;
  10762.                     $minstartliney $this->y;
  10763.                     $startlinepage $this->page;
  10764.                     if (isset($endlineposAND (!$pbrk)) {
  10765.                         $startlinepos $endlinepos;
  10766.                         unset($endlinepos);
  10767.                     else {
  10768.                         if (isset($this->footerlen[$this->page])) {
  10769.                             $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  10770.                         else {
  10771.                             $this->footerpos[$this->page$this->pagelen[$this->page];
  10772.                         }
  10773.                         $startlinepos $this->footerpos[$this->page];
  10774.                     }
  10775.                     $plalign $lalign;
  10776.                     if (isset($this->PageAnnots[$this->page])) {
  10777.                         $pask count($this->PageAnnots[$this->page]);
  10778.                     else {
  10779.                         $pask 0;
  10780.                     }
  10781.                 }
  10782.                 if (isset($opentagpos)) {
  10783.                     unset($opentagpos);
  10784.                 }
  10785.                 if ($dom[$key]['tag']{
  10786.                     if ($dom[$key]['opening']{
  10787.                         if ($dom[$key]['value'== 'table'{
  10788.                             if ($this->rtl{
  10789.                                 $wtmp $this->x $this->lMargin;
  10790.                             else {
  10791.                                 $wtmp $this->w $this->rMargin $this->x;
  10792.                             }
  10793.                             $wtmp -= ($this->cMargin);
  10794.                             // calculate cell width
  10795.                             if (isset($dom[$key]['width'])) {
  10796.                                 $table_width $this->getHTMLUnitToUnits($dom[$key]['width']$wtmp'px');
  10797.                             else {
  10798.                                 $table_width $wtmp;
  10799.                             }
  10800.                         }
  10801.                         // table content is handled in a special way
  10802.                         if (($dom[$key]['value'== 'td'OR ($dom[$key]['value'== 'th')) {
  10803.                             $trid $dom[$key]['parent'];
  10804.                             $table_el $dom[$trid]['parent'];
  10805.                             if (!isset($dom[$table_el]['cols'])) {
  10806.                                 $dom[$table_el]['cols'$trid['cols'];
  10807.                             }
  10808.                             if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  10809.                                 $currentcmargin $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding']1'px');
  10810.                             else {
  10811.                                 $currentcmargin 0;        
  10812.                             }
  10813.                             $this->cMargin $currentcmargin;
  10814.                             if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellspacing'])) {
  10815.                                 $cellspacing $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellspacing']1'px');
  10816.                             else {
  10817.                                 $cellspacing 0;
  10818.                             }
  10819.                             if ($this->rtl{
  10820.                                 $cellspacingx = -$cellspacing;
  10821.                             else {
  10822.                                 $cellspacingx $cellspacing;
  10823.                             }
  10824.                             $colspan $dom[$key]['attribute']['colspan'];
  10825.                             $wtmp ($colspan ($table_width $dom[$table_el]['cols']));
  10826.                             if (isset($dom[$key]['width'])) {
  10827.                                 $cellw $this->getHTMLUnitToUnits($dom[$key]['width']$wtmp'px');
  10828.                             else {
  10829.                                 $cellw $wtmp;
  10830.                             }
  10831.                             if (isset($dom[$key]['height'])) {
  10832.                                 // minimum cell height
  10833.                                 $cellh $this->getHTMLUnitToUnits($dom[$key]['height']0'px');
  10834.                             else {
  10835.                                 $cellh 0;
  10836.                             }
  10837.                             $cellw -= $cellspacing;
  10838.                             if (isset($dom[$key]['content'])) {
  10839.                                 $cell_content $dom[$key]['content'];
  10840.                             else {
  10841.                                 $cell_content '&nbsp;';
  10842.                             }
  10843.                             $tagtype $dom[$key]['value'];
  10844.                             $parentid $key;
  10845.                             while (($key $maxelAND (!(($dom[$key]['tag']AND (!$dom[$key]['opening']AND ($dom[$key]['value'== $tagtypeAND ($dom[$key]['parent'== $parentid)))) {
  10846.                                 // move $key index forward
  10847.                                 ++$key;
  10848.                             }
  10849.                             if (!isset($dom[$trid]['startpage'])) {
  10850.                                 $dom[$trid]['startpage'$this->page;
  10851.                             else {
  10852.                                 $this->setPage($dom[$trid]['startpage']);
  10853.                             }
  10854.                             if (!isset($dom[$trid]['starty'])) {
  10855.                                 $dom[$trid]['starty'$this->y;
  10856.                             else {
  10857.                                 $this->y $dom[$trid]['starty'];
  10858.                             }
  10859.                             if (!isset($dom[$trid]['startx'])) {
  10860.                                 $dom[$trid]['startx'$this->x;
  10861.                             }
  10862.                             $this->x += ($cellspacingx 2);                        
  10863.                             if (isset($dom[$parentid]['attribute']['rowspan'])) {
  10864.                                 $rowspan intval($dom[$parentid]['attribute']['rowspan']);
  10865.                             else {
  10866.                                 $rowspan 1;
  10867.                             }
  10868.                             // skip row-spanned cells started on the previous rows
  10869.                             if (isset($dom[$table_el]['rowspans'])) {
  10870.                                 $rsk 0;
  10871.                                 $rskmax count($dom[$table_el]['rowspans']);
  10872.                                 while ($rsk $rskmax{
  10873.                                     $trwsp $dom[$table_el]['rowspans'][$rsk];
  10874.                                     $rsstartx $trwsp['startx'];
  10875.                                     $rsendx $trwsp['endx'];
  10876.                                     // account for margin changes
  10877.                                     if ($trwsp['startpage'$this->page{
  10878.                                         if (($this->rtlAND ($this->pagedim[$this->page]['orm'!= $this->pagedim[$trwsp['startpage']]['orm'])) {
  10879.                                             $dl ($this->pagedim[$this->page]['orm'$this->pagedim[$trwsp['startpage']]['orm']);
  10880.                                             $rsstartx -= $dl;
  10881.                                             $rsendx -= $dl;
  10882.                                         elseif ((!$this->rtlAND ($this->pagedim[$this->page]['olm'!= $this->pagedim[$trwsp['startpage']]['olm'])) {
  10883.                                             $dl ($this->pagedim[$this->page]['olm'$this->pagedim[$trwsp['startpage']]['olm']);
  10884.                                             $rsstartx += $dl;
  10885.                                             $rsendx += $dl;
  10886.                                         }
  10887.                                     }
  10888.                                     if  (($trwsp['rowspan'0)
  10889.                                         AND ($rsstartx ($this->x $cellspacing $currentcmargin $this->feps)) 
  10890.                                         AND ($rsstartx ($this->x $cellspacing $currentcmargin $this->feps))
  10891.                                         AND (($trwsp['starty'($this->y $this->feps)) OR ($trwsp['startpage'$this->page))) {
  10892.                                         $this->x $rsendx $cellspacingx;
  10893.                                         if (($trwsp['rowspan'== 1
  10894.                                             AND (isset($dom[$trid]['endy'])) 
  10895.                                             AND (isset($dom[$trid]['endpage'])) 
  10896.                                             AND ($trwsp['endpage'== $dom[$trid]['endpage'])) {
  10897.                                             $dom[$table_el]['rowspans'][$rsk]['endy'max($dom[$trid]['endy']$trwsp['endy']);
  10898.                                             $dom[$trid]['endy'$dom[$table_el]['rowspans'][$rsk]['endy'];
  10899.                                         }
  10900.                                         $rsk 0;
  10901.                                     else {
  10902.                                         ++$rsk;
  10903.                                     }
  10904.                                 }
  10905.                             }
  10906.                             // add rowspan information to table element
  10907.                             if ($rowspan 1{
  10908.                                 if (isset($this->footerlen[$this->page])) {
  10909.                                     $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  10910.                                 else {
  10911.                                     $this->footerpos[$this->page$this->pagelen[$this->page];
  10912.                                 }
  10913.                                 $trintmrkpos $this->footerpos[$this->page];
  10914.                                 $trsid array_push($dom[$table_el]['rowspans']array('trid' => $trid'rowspan' => $rowspan'mrowspan' => $rowspan'colspan' => $colspan'startpage' => $this->page'startx' => $this->x'starty' => $this->y'intmrkpos' => $trintmrkpos));
  10915.                             }
  10916.                             $cellid array_push($dom[$trid]['cellpos']array('startx' => $this->x));
  10917.                             if ($rowspan 1{
  10918.                                 $dom[$trid]['cellpos'][($cellid 1)]['rowspanid'($trsid 1);
  10919.                             }
  10920.                             // push background colors
  10921.                             if (isset($dom[$parentid]['bgcolor']AND ($dom[$parentid]['bgcolor'!== false)) {
  10922.                                 $dom[$trid]['cellpos'][($cellid 1)]['bgcolor'$dom[$parentid]['bgcolor'];
  10923.                             }
  10924.                             $prevLastH$this->lasth;
  10925.                             // ****** write the cell content ******
  10926.                             $this->MultiCell($cellw$cellh$cell_contentfalse$lalignfalse2''''true0true);
  10927.                             $this->lasth $prevLastH;
  10928.                             $this->cMargin $currentcmargin;
  10929.                             $dom[$trid]['cellpos'][($cellid 1)]['endx'$this->x;
  10930.                             // update the end of row position
  10931.                             if ($rowspan <= 1{
  10932.                                 if (isset($dom[$trid]['endy'])) {
  10933.                                     if ($this->page == $dom[$trid]['endpage']{
  10934.                                         $dom[$trid]['endy'max($this->y$dom[$trid]['endy']);
  10935.                                     elseif ($this->page $dom[$trid]['endpage']{
  10936.                                         $dom[$trid]['endy'$this->y;
  10937.                                     }
  10938.                                 else {
  10939.                                     $dom[$trid]['endy'$this->y;
  10940.                                 }
  10941.                                 if (isset($dom[$trid]['endpage'])) {
  10942.                                     $dom[$trid]['endpage'max($this->page$dom[$trid]['endpage']);
  10943.                                 else {
  10944.                                     $dom[$trid]['endpage'$this->page;
  10945.                                 }
  10946.                             else {
  10947.                                 // account for row-spanned cells
  10948.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endx'$this->x;
  10949.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endy'$this->y;
  10950.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endpage'$this->page;                
  10951.                             }
  10952.                             if (isset($dom[$table_el]['rowspans'])) {
  10953.                                 foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  10954.                                     if ($trwsp['rowspan'0{
  10955.                                         if (isset($dom[$trid]['endpage'])) {
  10956.                                             if ($trwsp['endpage'== $dom[$trid]['endpage']{
  10957.                                                 $dom[$table_el]['rowspans'][$k]['endy'max($dom[$trid]['endy']$trwsp['endy']);
  10958.                                             elseif ($trwsp['endpage'$dom[$trid]['endpage']{
  10959.                                                 $dom[$table_el]['rowspans'][$k]['endy'$dom[$trid]['endy'];
  10960.                                                 $dom[$table_el]['rowspans'][$k]['endpage'$dom[$trid]['endpage'];
  10961.                                             else {
  10962.                                                 $dom[$trid]['endy'$this->pagedim[$dom[$trid]['endpage']]['hk'$this->pagedim[$dom[$trid]['endpage']]['bm'];
  10963.                                             }
  10964.                                         }
  10965.                                     }
  10966.                                 }
  10967.                             }
  10968.                             $this->x += ($cellspacingx 2);
  10969.                         else {
  10970.                             // opening tag (or self-closing tag)
  10971.                             if (!isset($opentagpos)) {
  10972.                                 if (isset($this->footerlen[$this->page])) {
  10973.                                     $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  10974.                                 else {
  10975.                                     $this->footerpos[$this->page$this->pagelen[$this->page];
  10976.                                 }
  10977.                                 $opentagpos $this->footerpos[$this->page];
  10978.                             }
  10979.                             
  10980.                             $this->openHTMLTagHandler($dom$key$cell);
  10981.                         }
  10982.                     else {
  10983.                         // closing tag
  10984.                         $this->closeHTMLTagHandler($dom$key$cell);
  10985.                     }
  10986.                 elseif (strlen($dom[$key]['value']0{
  10987.                     // print list-item
  10988.                     if (!empty($this->lispacer)) {
  10989.                         $this->SetFont($pfontname$pfontstyle$pfontsize);
  10990.                         $this->lasth $this->FontSize $this->cell_height_ratio;
  10991.                         $minstartliney $this->y;
  10992.                         $this->putHtmlListBullet($this->listnum$this->lispacer$pfontsize);
  10993.                         $this->SetFont($curfontname$curfontstyle$curfontsize);
  10994.                         $this->lasth $this->FontSize $this->cell_height_ratio;
  10995.                         if (is_numeric($pfontsizeAND ($pfontsize 0AND is_numeric($curfontsizeAND ($curfontsize 0AND ($pfontsize != $curfontsize)) {
  10996.                             $this->y += (($pfontsize $curfontsize$this->k);
  10997.                             $minstartliney min($this->y$minstartliney);
  10998.                         }
  10999.                     }
  11000.                     // text
  11001.                     $this->htmlvspace 0;
  11002.                     if ((!$this->premodeAND ($this->rtl OR $this->tmprtl)) {
  11003.                         // reverse spaces order
  11004.                         $len1 strlen($dom[$key]['value']);
  11005.                         $lsp $len1 strlen(ltrim($dom[$key]['value']));
  11006.                         $rsp $len1 strlen(rtrim($dom[$key]['value']));
  11007.                         $tmpstr '';
  11008.                         if ($rsp 0{
  11009.                             $tmpstr .= substr($dom[$key]['value']-$rsp);
  11010.                         }
  11011.                         $tmpstr .= trim($dom[$key]['value']);
  11012.                         if ($lsp 0{
  11013.                             $tmpstr .= substr($dom[$key]['value']0$lsp);
  11014.                         }
  11015.                         $dom[$key]['value'$tmpstr;
  11016.                     }
  11017.                     if ($newline{
  11018.                         if (!$this->premode{
  11019.                             if (($this->rtl OR $this->tmprtl)) {
  11020.                                 $dom[$key]['value'rtrim($dom[$key]['value']);
  11021.                             else {
  11022.                                 $dom[$key]['value'ltrim($dom[$key]['value']);
  11023.                             }
  11024.                         }
  11025.                         $newline false;
  11026.                         $firstblock true;
  11027.                     else {
  11028.                         $firstblock false;
  11029.                     }
  11030.                     $strrest '';
  11031.                     if (!empty($this->HREF)) {
  11032.                         // HTML <a> Link
  11033.                         $strrest $this->addHtmlLink($this->HREF['url']$dom[$key]['value']$wfilltrue$this->HREF['color']$this->HREF['style']);
  11034.                     else {
  11035.                         $ctmpmargin $this->cMargin;
  11036.                         $this->cMargin 0;
  11037.                         // ****** write only until the end of the line and get the rest ******
  11038.                         $strrest $this->Write($this->lasth$dom[$key]['value']''$wfill''false0true$firstblock);
  11039.                         $this->cMargin $ctmpmargin;
  11040.                     }
  11041.                     if (strlen($strrest0{
  11042.                         // store the remaining string on the previous $key position
  11043.                         $this->newline true;
  11044.                         if ($cell{
  11045.                             if ($this->rtl{
  11046.                                 $this->x -= $this->cMargin;
  11047.                             else {
  11048.                                 $this->x += $this->cMargin;
  11049.                             }
  11050.                         }
  11051.                         if ($strrest == $dom[$key]['value']{
  11052.                             // used to avoid infinite loop
  11053.                             ++$loop;
  11054.                         else {
  11055.                             $loop 0;
  11056.                         }
  11057.                         $dom[$key]['value'ltrim($strrest);
  11058.                         if ($loop 3{
  11059.                             --$key;
  11060.                         }
  11061.                     else {
  11062.                         $loop 0;
  11063.                     }
  11064.                 }
  11065.                 ++$key;
  11066.             // end for each $key
  11067.             // align the last line
  11068.             if (isset($startlinex)) {
  11069.                 $yshift $minstartliney $startliney;
  11070.                 if (($yshift 0OR ($this->page $startlinepage)) {
  11071.                     $yshift 0;
  11072.                 }
  11073.                 if ((isset($plalignAND ((($plalign == 'C'OR ($plalign == 'J'OR (($plalign == 'R'AND (!$this->rtl)) OR (($plalign == 'L'AND ($this->rtl))))) OR ($yshift 0)) {
  11074.                     // the last line must be shifted to be aligned as requested
  11075.                     $linew abs($this->endlinex $startlinex);
  11076.                     $pstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  11077.                     if (isset($opentagposAND isset($this->footerlen[$startlinepage])) {
  11078.                         $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11079.                         $midpos min($opentagpos$this->footerpos[$startlinepage]);
  11080.                     elseif (isset($opentagpos)) {
  11081.                         $midpos $opentagpos;
  11082.                     elseif (isset($this->footerlen[$startlinepage])) {
  11083.                         $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11084.                         $midpos $this->footerpos[$startlinepage];
  11085.                     else {
  11086.                         $midpos 0;
  11087.                     }
  11088.                     if ($midpos 0{
  11089.                         $pmid substr($this->getPageBuffer($startlinepage)$startlinepos($midpos $startlinepos));
  11090.                         $pend substr($this->getPageBuffer($startlinepage)$midpos);
  11091.                     else {
  11092.                         $pmid substr($this->getPageBuffer($startlinepage)$startlinepos);
  11093.                         $pend '';
  11094.                     }
  11095.                     // calculate shifting amount
  11096.                     $tw $w;
  11097.                     if ($this->lMargin != $prevlMargin{
  11098.                         $tw += ($prevlMargin $this->lMargin);
  11099.                     }
  11100.                     if ($this->rMargin != $prevrMargin{
  11101.                         $tw += ($prevrMargin $this->rMargin);
  11102.                     }
  11103.                     $mdiff abs($tw $linew);
  11104.                     if ($plalign == 'C'{
  11105.                         if ($this->rtl{
  11106.                             $t_x = -($mdiff 2);
  11107.                         else {
  11108.                             $t_x ($mdiff 2);
  11109.                         }
  11110.                     elseif (($plalign == 'R'AND (!$this->rtl)) {
  11111.                         // right alignment on LTR document
  11112.                         $t_x $mdiff;
  11113.                     elseif (($plalign == 'L'AND ($this->rtl)) {
  11114.                         // left alignment on RTL document
  11115.                         $t_x = -$mdiff;
  11116.                     else {
  11117.                         $t_x 0;
  11118.                     }
  11119.                     if (($t_x != 0OR ($yshift 0)) {
  11120.                         // shift the line
  11121.                         $trx sprintf('1 0 0 1 %.3f %.3f cm'($t_x $this->k)($yshift $this->k));
  11122.                         $this->setPageBuffer($startlinepage$pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend);
  11123.                         $endlinepos strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n");
  11124.                         // shift the annotations and links
  11125.                         if (isset($this->PageAnnots[$this->page])) {
  11126.                             foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  11127.                                 if ($pak >= $pask{
  11128.                                     $this->PageAnnots[$this->page][$pak]['x'+= $t_x;
  11129.                                     $this->PageAnnots[$this->page][$pak]['y'-= $yshift;
  11130.                                 }
  11131.                             }
  11132.                         }
  11133.                         $this->y -= $yshift;
  11134.                     }
  11135.                 }
  11136.             }
  11137.             if ($ln AND (!($cell AND ($dom[$key-1]['value'== 'table')))) {
  11138.                 $this->Ln($this->lasth);
  11139.             }
  11140.             // restore previous values
  11141.             $this->setGraphicVars($gvars);
  11142.             if ($this->page $prevPage{
  11143.                 $this->lMargin $this->pagedim[$this->page]['olm'];
  11144.                 $this->rMargin $this->pagedim[$this->page]['orm'];
  11145.             }
  11146.             unset($dom);
  11147.         }
  11148.         
  11149.         /**
  11150.          * Process opening tags.
  11151.          * @param array $dom html dom array
  11152.          * @param int $key current element id
  11153.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  11154.          * @access protected
  11155.          */
  11156.         protected function openHTMLTagHandler(&$dom$key$cell=false{
  11157.             $tag $dom[$key];
  11158.             $parent $dom[($dom[$key]['parent'])];
  11159.             $firstorlast ($key == 1);
  11160.             // check for text direction attribute
  11161.             if (isset($tag['attribute']['dir'])) {
  11162.                 $this->tmprtl $tag['attribute']['dir'== 'rtl' 'R' 'L';
  11163.             else {
  11164.                 $this->tmprtl false;
  11165.             }
  11166.             //Opening tag
  11167.             switch($tag['value']{
  11168.                 case 'table'{
  11169.                     $cp 0;
  11170.                     $cs 0;
  11171.                     $dom[$key]['rowspans'array();
  11172.                     if (isset($tag['attribute']['cellpadding'])) {
  11173.                         $cp $this->getHTMLUnitToUnits($tag['attribute']['cellpadding']1'px');
  11174.                         $this->oldcMargin $this->cMargin;
  11175.                         $this->cMargin $cp;
  11176.                     }
  11177.                     if (isset($tag['attribute']['cellspacing'])) {
  11178.                         $cs $this->getHTMLUnitToUnits($tag['attribute']['cellspacing']1'px');
  11179.                     }
  11180.                     $this->checkPageBreak(($cp($cs$this->lasth);
  11181.                     break;
  11182.                 }
  11183.                 case 'tr'{
  11184.                     // array of columns positions
  11185.                     $dom[$key]['cellpos'array();
  11186.                     break;
  11187.                 }
  11188.                 case 'hr'{
  11189.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  11190.                     $this->htmlvspace 0;
  11191.                     $wtmp $this->w $this->lMargin $this->rMargin;
  11192.                     if ((isset($tag['attribute']['width'])) AND ($tag['attribute']['width'!= '')) {
  11193.                         $hrWidth $this->getHTMLUnitToUnits($tag['attribute']['width']$wtmp'px');
  11194.                     else {
  11195.                         $hrWidth $wtmp;
  11196.                     }
  11197.                     $x $this->GetX();
  11198.                     $y $this->GetY();
  11199.                     $prevlinewidth $this->GetLineWidth();
  11200.                     $this->Line($x$y$x $hrWidth$y);
  11201.                     $this->SetLineWidth($prevlinewidth);
  11202.                     $this->addHTMLVertSpace(1$cell''!isset($dom[($key 1)])$tag['value']false);
  11203.                     break;
  11204.                 }
  11205.                 case 'a'{
  11206.                     if (array_key_exists('href'$tag['attribute'])) {
  11207.                         $this->HREF['url'$tag['attribute']['href'];
  11208.                     }
  11209.                     $this->HREF['color'$this->htmlLinkColorArray;
  11210.                     $this->HREF['style'$this->htmlLinkFontStyle;
  11211.                     if (array_key_exists('style'$tag['attribute'])) {
  11212.                         // get style attributes
  11213.                         preg_match_all('/([^;:\s]*):([^;]*)/'$tag['attribute']['style']$style_arrayPREG_PATTERN_ORDER);
  11214.                         $astyle array();
  11215.                         while (list($id$nameeach($style_array[1])) {
  11216.                             $name strtolower($name);
  11217.                             $astyle[$nametrim($style_array[2][$id]);
  11218.                         }
  11219.                         if (isset($astyle['color'])) {
  11220.                             $this->HREF['color'$this->convertHTMLColorToDec($astyle['color']);
  11221.                         }
  11222.                         if (isset($astyle['text-decoration'])) {
  11223.                             $this->HREF['style''';
  11224.                             $decors explode(' 'strtolower($astyle['text-decoration']));
  11225.                             foreach ($decors as $dec{
  11226.                                 $dec trim($dec);
  11227.                                 if (!empty($dec)) {
  11228.                                     if ($dec{0== 'u'{
  11229.                                         $this->HREF['style'.= 'U';
  11230.                                     elseif ($dec{0== 'l'{
  11231.                                         $this->HREF['style'.= 'D';
  11232.                                     }
  11233.                                 }
  11234.                             }
  11235.                         }
  11236.                     }        
  11237.                     break;
  11238.                 }
  11239.                 case 'img'{
  11240.                     if (isset($tag['attribute']['src'])) {
  11241.                         // replace relative path with real server path
  11242.                         if ($tag['attribute']['src'][0== '/'{
  11243.                             $tag['attribute']['src'$_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
  11244.                         }
  11245.                         $tag['attribute']['src'urldecode($tag['attribute']['src']);
  11246.                         $tag['attribute']['src'str_replace(K_PATH_URLK_PATH_MAIN$tag['attribute']['src']);
  11247.                         if (!isset($tag['attribute']['width'])) {
  11248.                             $tag['attribute']['width'0;
  11249.                         }
  11250.                         if (!isset($tag['attribute']['height'])) {
  11251.                             $tag['attribute']['height'0;
  11252.                         }
  11253.                         //if (!isset($tag['attribute']['align'])) {
  11254.                             // the only alignment supported is "bottom"
  11255.                             // further development is required for other modes.
  11256.                             $tag['attribute']['align''bottom';
  11257.                         //} 
  11258.                         switch($tag['attribute']['align']{
  11259.                             case 'top'{
  11260.                                 $align 'T';
  11261.                                 break;
  11262.                             }
  11263.                             case 'middle'{
  11264.                                 $align 'M';
  11265.                                 break;
  11266.                             }
  11267.                             case 'bottom'{
  11268.                                 $align 'B';
  11269.                                 break;
  11270.                             }
  11271.                             default{
  11272.                                 $align 'B';
  11273.                                 break;
  11274.                             }
  11275.                         }
  11276.                         $fileinfo pathinfo($tag['attribute']['src']);
  11277.                         if (isset($fileinfo['extension']AND (!empty($fileinfo['extension']))) {
  11278.                             $type strtolower($fileinfo['extension']);
  11279.                         }
  11280.                         $prevy $this->y;
  11281.                         $xpos $this->GetX();
  11282.                         if (isset($dom[($key 1)]AND ($dom[($key 1)]['value'== ' ')) {
  11283.                             if ($this->rtl{
  11284.                                 $xpos += $this->GetStringWidth(' ');
  11285.                             else {
  11286.                                 $xpos -= $this->GetStringWidth(' ');
  11287.                             }
  11288.                         }
  11289.                         $imglink '';
  11290.                         if (isset($this->HREF['url']AND !empty($this->HREF['url'])) {
  11291.                             $imglink $this->HREF['url'];
  11292.                             if ($imglink{0== '#'{
  11293.                                 // convert url to internal link
  11294.                                 $page intval(substr($imglink1));
  11295.                                 $imglink $this->AddLink();
  11296.                                 $this->SetLink($imglink0$page);
  11297.                             }
  11298.                         }
  11299.                         $border 0;
  11300.                         if (isset($tag['attribute']['border']AND !empty($tag['attribute']['border'])) {
  11301.                             // currently only support 1 (frame) or a combination of 'LTRB'
  11302.                             $border $tag['attribute']['border'];
  11303.                         }
  11304.                         if (($type == 'eps'OR ($type == 'ai')) {
  11305.                             $this->ImageEps($tag['attribute']['src']$xpos$this->GetY()$this->pixelsToUnits($tag['attribute']['width'])$this->pixelsToUnits($tag['attribute']['height'])$imglinktrue$align''$border);
  11306.                         else {
  11307.                             $this->Image($tag['attribute']['src']$xpos$this->GetY()$this->pixelsToUnits($tag['attribute']['width'])$this->pixelsToUnits($tag['attribute']['height'])''$imglink$alignfalse300''falsefalse$border);
  11308.                         }
  11309.                         switch($align{
  11310.                             case 'T'{
  11311.                                 $this->y $prevy;
  11312.                                 break;
  11313.                             }
  11314.                             case 'M'{
  11315.                                 $this->y (($this->img_rb_y $prevy ($tag['fontsize'$this->k)) 2;
  11316.                                 break;
  11317.                             }
  11318.                             case 'B'{
  11319.                                 $this->y $this->img_rb_y ($tag['fontsize'$this->k);
  11320.                                 break;
  11321.                             }
  11322.                         }
  11323.                     }
  11324.                     break;
  11325.                 }
  11326.                 case 'dl'{
  11327.                     ++$this->listnum;
  11328.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  11329.                     break;
  11330.                 }
  11331.                 case 'dt'{
  11332.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  11333.                     break;
  11334.                 }
  11335.                 case 'dd'{
  11336.                     if ($this->rtl{
  11337.                         $this->rMargin += $this->listindent;
  11338.                     else {
  11339.                         $this->lMargin += $this->listindent;
  11340.                     }
  11341.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  11342.                     break;
  11343.                 }
  11344.                 case 'ul':
  11345.                 case 'ol'{
  11346.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  11347.                     $this->htmlvspace 0;
  11348.                     ++$this->listnum;
  11349.                     if ($tag['value'== 'ol'{
  11350.                         $this->listordered[$this->listnumtrue;
  11351.                     else {
  11352.                         $this->listordered[$this->listnumfalse;
  11353.                     }
  11354.                     if (isset($tag['attribute']['start'])) {
  11355.                         $this->listcount[$this->listnumintval($tag['attribute']['start']1;
  11356.                     else {
  11357.                         $this->listcount[$this->listnum0;
  11358.                     }
  11359.                     if ($this->rtl{
  11360.                         $this->rMargin += $this->listindent;
  11361.                     else {
  11362.                         $this->lMargin += $this->listindent;
  11363.                     }
  11364.                     break;
  11365.                 }
  11366.                 case 'li'{
  11367.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);                
  11368.                     if ($this->listordered[$this->listnum]{
  11369.                         // ordered item
  11370.                         if (!empty($parent['attribute']['type'])) {
  11371.                             $this->lispacer $parent['attribute']['type'];
  11372.                         elseif (!empty($parent['listtype'])) {
  11373.                             $this->lispacer $parent['listtype'];
  11374.                         elseif (!empty($this->lisymbol)) {
  11375.                             $this->lispacer $this->lisymbol;
  11376.                         else {
  11377.                             $this->lispacer '#';
  11378.                         }
  11379.                         ++$this->listcount[$this->listnum];
  11380.                         if (isset($tag['attribute']['value'])) {
  11381.                             $this->listcount[$this->listnumintval($tag['attribute']['value']);
  11382.                         }
  11383.                     else {
  11384.                         // unordered item
  11385.                         if (!empty($parent['listtype'])) {
  11386.                             $this->lispacer $parent['listtype'];
  11387.                         elseif (!empty($this->lisymbol)) {
  11388.                             $this->lispacer $this->lisymbol;
  11389.                         else {
  11390.                             $this->lispacer '!';
  11391.                         }
  11392.                     }
  11393.                     break;
  11394.                 }
  11395.                 case 'blockquote'{
  11396.                     if ($this->rtl{
  11397.                         $this->rMargin += $this->listindent;
  11398.                     else {
  11399.                         $this->lMargin += $this->listindent;
  11400.                     }
  11401.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']false);
  11402.                     break;
  11403.                 }
  11404.                 case 'br'{
  11405.                     $this->Ln(''$cell);
  11406.                     break;
  11407.                 }
  11408.                 case 'div'{
  11409.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  11410.                     break;
  11411.                 }
  11412.                 case 'p'{
  11413.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']false);
  11414.                     break;
  11415.                 }
  11416.                 case 'pre'{
  11417.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  11418.                     $this->premode true;
  11419.                     break;
  11420.                 }
  11421.                 case 'sup'{
  11422.                     $this->SetXY($this->GetX()$this->GetY(((0.7 $this->FontSizePt$this->k));
  11423.                     break;
  11424.                 }
  11425.                 case 'sub'{
  11426.                     $this->SetXY($this->GetX()$this->GetY(((0.3 $this->FontSizePt$this->k));
  11427.                     break;
  11428.                 }
  11429.                 case 'h1'
  11430.                 case 'h2'
  11431.                 case 'h3'
  11432.                 case 'h4'
  11433.                 case 'h5'
  11434.                 case 'h6'{
  11435.                     $this->addHTMLVertSpace(1$cell($tag['fontsize'1.5$this->k$firstorlast$tag['value']false);
  11436.                     break;
  11437.                 }
  11438.                 default{
  11439.                     break;
  11440.                 }
  11441.             }
  11442.         }
  11443.         
  11444.         /**
  11445.          * Process closing tags.
  11446.          * @param array $dom html dom array
  11447.          * @param int $key current element id
  11448.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  11449.          * @access protected
  11450.          */
  11451.         protected function closeHTMLTagHandler(&$dom$key$cell=false{
  11452.             $tag $dom[$key];
  11453.             $parent $dom[($dom[$key]['parent'])];
  11454.             $firstorlast ((!isset($dom[($key 1)])) OR ((!isset($dom[($key 2)])) AND ($dom[($key 1)]['value'== 'marker')));
  11455.             //Closing tag
  11456.             switch($tag['value']{
  11457.                 case 'tr'{
  11458.                     $table_el $dom[($dom[$key]['parent'])]['parent'];
  11459.                     if(!isset($parent['endy'])) {
  11460.                         $dom[($dom[$key]['parent'])]['endy'$this->y;
  11461.                         $parent['endy'$this->y;
  11462.                     }
  11463.                     if(!isset($parent['endpage'])) {
  11464.                         $dom[($dom[$key]['parent'])]['endpage'$this->page;
  11465.                         $parent['endpage'$this->page;
  11466.                     }
  11467.                     // update row-spanned cells
  11468.                     if (isset($dom[$table_el]['rowspans'])) {
  11469.                         foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  11470.                             $dom[$table_el]['rowspans'][$k]['rowspan'-= 1;
  11471.                             if ($dom[$table_el]['rowspans'][$k]['rowspan'== 0{
  11472.                                 if ($dom[$table_el]['rowspans'][$k]['endpage'== $parent['endpage']{
  11473.                                     $dom[($dom[$key]['parent'])]['endy'max($dom[$table_el]['rowspans'][$k]['endy']$parent['endy']);
  11474.                                 elseif ($dom[$table_el]['rowspans'][$k]['endpage'$parent['endpage']{
  11475.                                     $dom[($dom[$key]['parent'])]['endy'$dom[$table_el]['rowspans'][$k]['endy'];
  11476.                                     $dom[($dom[$key]['parent'])]['endpage'$dom[$table_el]['rowspans'][$k]['endpage'];
  11477.                                 }
  11478.                             }
  11479.                         }
  11480.                     }
  11481.                     $this->setPage($parent['endpage']);
  11482.                     $this->y $parent['endy'];
  11483.                     if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  11484.                         $cellspacing $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing']1'px');
  11485.                         $this->y += $cellspacing;
  11486.                     }                
  11487.                     $this->Ln(0$cell);
  11488.                     $this->x $parent['startx'];
  11489.                     // account for booklet mode
  11490.                     if ($this->page $parent['startpage']{
  11491.                         if (($this->rtlAND ($this->pagedim[$this->page]['orm'!= $this->pagedim[$parent['startpage']]['orm'])) {
  11492.                             $this->x += ($this->pagedim[$this->page]['orm'$this->pagedim[$parent['startpage']]['orm']);
  11493.                         elseif ((!$this->rtlAND ($this->pagedim[$this->page]['olm'!= $this->pagedim[$parent['startpage']]['olm'])) {
  11494.                             $this->x += ($this->pagedim[$this->page]['olm'$this->pagedim[$parent['startpage']]['olm']);
  11495.                         }
  11496.                     }
  11497.                     break;
  11498.                 }
  11499.                 case 'table'{
  11500.                     // draw borders
  11501.                     $table_el $parent;
  11502.                     if ((isset($table_el['attribute']['border']AND ($table_el['attribute']['border'0)) 
  11503.                         OR (isset($table_el['style']['border']AND ($table_el['style']['border'0))) {
  11504.                             $border 1;
  11505.                     else {
  11506.                         $border 0;
  11507.                     }
  11508.                     // fix bottom line alignment of last line before page break
  11509.                     foreach ($dom[($dom[$key]['parent'])]['trids'as $j => $trkey{
  11510.                         // update row-spanned cells
  11511.                         if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  11512.                             foreach ($dom[($dom[$key]['parent'])]['rowspans'as $k => $trwsp{
  11513.                                 if ($trwsp['trid'== $trkey{
  11514.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'-= 1;
  11515.                                 }
  11516.                                 if (isset($prevtrkeyAND ($trwsp['trid'== $prevtrkeyAND ($trwsp['mrowspan'>= 0)) {
  11517.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'$trkey;
  11518.                                 }
  11519.                             }
  11520.                         }
  11521.                         if (isset($prevtrkeyAND ($dom[$trkey]['startpage'$dom[$prevtrkey]['endpage'])) {
  11522.                             $pgendy $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'$this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  11523.                             $dom[$prevtrkey]['endy'$pgendy;
  11524.                             // update row-spanned cells
  11525.                             if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  11526.                                 foreach ($dom[($dom[$key]['parent'])]['rowspans'as $k => $trwsp{
  11527.                                     if (($trwsp['trid'== $trkeyAND ($trwsp['mrowspan'== 1AND ($trwsp['endpage'== $dom[$prevtrkey]['endpage'])) {
  11528.                                         $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'$pgendy;
  11529.                                         $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'= -1;
  11530.                                     }
  11531.                                 }
  11532.                             }
  11533.                         }
  11534.                         $prevtrkey $trkey;
  11535.                         $table_el $dom[($dom[$key]['parent'])];
  11536.                     }
  11537.                     // for each row
  11538.                     foreach ($table_el['trids'as $j => $trkey{
  11539.                         $parent $dom[$trkey];
  11540.                         // for each cell on the row
  11541.                         foreach ($parent['cellpos'as $k => $cellpos{
  11542.                             if (isset($cellpos['rowspanid']AND ($cellpos['rowspanid'>= 0)) {
  11543.                                 $cellpos['startx'$table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  11544.                                 $cellpos['endx'$table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  11545.                                 $endy $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  11546.                                 $startpage $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  11547.                                 $endpage $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  11548.                             else {
  11549.                                 $endy $parent['endy'];
  11550.                                 $startpage $parent['startpage'];
  11551.                                 $endpage $parent['endpage'];
  11552.                             }
  11553.                             if ($endpage $startpage{
  11554.                                 // design borders around HTML cells.
  11555.                                 for ($page=$startpage$page <= $endpage++$page{
  11556.                                     $this->setPage($page);
  11557.                                     if ($page == $startpage{
  11558.                                         $this->y $parent['starty']// put cursor at the beginning of row on the first page
  11559.                                         $ch $this->getPageHeight($parent['starty'$this->getBreakMargin();
  11560.                                         $cborder $this->getBorderMode($border$position='start');
  11561.                                     elseif ($page == $endpage{
  11562.                                         $this->y $this->tMargin// put cursor at the beginning of last page
  11563.                                         $ch $endy $this->tMargin;
  11564.                                         $cborder $this->getBorderMode($border$position='end');
  11565.                                     else {
  11566.                                         $this->y $this->tMargin// put cursor at the beginning of the current page
  11567.                                         $ch $this->getPageHeight($this->tMargin $this->getBreakMargin();
  11568.                                         $cborder $this->getBorderMode($border$position='middle');
  11569.                                     }
  11570.                                     if (isset($cellpos['bgcolor']AND ($cellpos['bgcolor']!== false{
  11571.                                         $this->SetFillColorArray($cellpos['bgcolor']);
  11572.                                         $fill true;
  11573.                                     else {
  11574.                                         $fill false;
  11575.                                     }
  11576.                                     $cw abs($cellpos['endx'$cellpos['startx']);
  11577.                                     $this->x $cellpos['startx'];
  11578.                                     // account for margin changes
  11579.                                     if ($page $startpage{
  11580.                                         if (($this->rtlAND ($this->pagedim[$page]['orm'!= $this->pagedim[$startpage]['orm'])) {
  11581.                                             $this->x -= ($this->pagedim[$page]['orm'$this->pagedim[$startpage]['orm']);
  11582.                                         elseif ((!$this->rtlAND ($this->pagedim[$page]['lm'!= $this->pagedim[$startpage]['olm'])) {
  11583.                                             $this->x += ($this->pagedim[$page]['olm'$this->pagedim[$startpage]['olm']);
  11584.                                         }
  11585.                                     }
  11586.                                     // design a cell around the text
  11587.                                     $ccode $this->FillColor."\n".$this->getCellCode($cw$ch''$cborder1''$fill);
  11588.                                     if ($cborder OR $fill{
  11589.                                         $pstart substr($this->getPageBuffer($this->page)0$this->intmrk[$this->page]);
  11590.                                         $pend substr($this->getPageBuffer($this->page)$this->intmrk[$this->page]);
  11591.                                         $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  11592.                                         $this->intmrk[$this->page+= strlen($ccode."\n");
  11593.                                     }
  11594.                                 }
  11595.                             else {
  11596.                                 $this->setPage($startpage);
  11597.                                 $ch $endy $parent['starty'];
  11598.                                 if (isset($cellpos['bgcolor']AND ($cellpos['bgcolor']!== false{
  11599.                                     $this->SetFillColorArray($cellpos['bgcolor']);
  11600.                                     $fill true;
  11601.                                 else {
  11602.                                     $fill false;
  11603.                                 }
  11604.                                 $cw abs($cellpos['endx'$cellpos['startx']);
  11605.                                 $this->x $cellpos['startx'];
  11606.                                 $this->y $parent['starty'];
  11607.                                 // design a cell around the text
  11608.                                 $ccode $this->FillColor."\n".$this->getCellCode($cw$ch''$border1''$fill);
  11609.                                 if ($border OR $fill{
  11610.                                     if (end($this->transfmrk[$this->page]!== false{
  11611.                                         $pagemarkkey key($this->transfmrk[$this->page]);
  11612.                                         $pagemark &$this->transfmrk[$this->page][$pagemarkkey];
  11613.                                     elseif ($this->InFooter{
  11614.                                         $pagemark &$this->footerpos[$this->page];
  11615.                                     else {
  11616.                                         $pagemark &$this->intmrk[$this->page];
  11617.                                     }
  11618.                                     $pstart substr($this->getPageBuffer($this->page)0$pagemark);
  11619.                                     $pend substr($this->getPageBuffer($this->page)$pagemark);
  11620.                                     $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  11621.                                     $pagemark += strlen($ccode."\n");
  11622.                                 }                    
  11623.                             }
  11624.                         }                    
  11625.                         if (isset($table_el['attribute']['cellspacing'])) {
  11626.                             $cellspacing $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing']1'px');
  11627.                             $this->y += $cellspacing;
  11628.                         }                
  11629.                         $this->Ln(0$cell);
  11630.                         $this->x $parent['startx'];
  11631.                         if ($endpage $startpage{
  11632.                             if (($this->rtlAND ($this->pagedim[$endpage]['orm'!= $this->pagedim[$startpage]['orm'])) {
  11633.                                 $this->x += ($this->pagedim[$endpage]['orm'$this->pagedim[$startpage]['orm']);
  11634.                             elseif ((!$this->rtlAND ($this->pagedim[$endpage]['olm'!= $this->pagedim[$startpage]['olm'])) {
  11635.                                 $this->x += ($this->pagedim[$endpage]['olm'$this->pagedim[$startpage]['olm']);
  11636.                             }
  11637.                         }
  11638.                     }
  11639.                     if (isset($parent['cellpadding'])) {
  11640.                         $this->cMargin $this->oldcMargin;
  11641.                     }
  11642.                     $this->lasth $this->FontSize $this->cell_height_ratio;
  11643.                     break;
  11644.                 }
  11645.                 case 'a'{
  11646.                     $this->HREF '';
  11647.                     break;
  11648.                 }
  11649.                 case 'sup'{
  11650.                     $this->SetXY($this->GetX()$this->GetY(((0.7 $parent['fontsize']$this->k));
  11651.                     break;
  11652.                 }
  11653.                 case 'sub'{
  11654.                     $this->SetXY($this->GetX()$this->GetY(((0.3 $parent['fontsize'])/$this->k));
  11655.                     break;
  11656.                 }
  11657.                 case 'div'{
  11658.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']true);
  11659.                     break;
  11660.                 }
  11661.                 case 'blockquote'{
  11662.                     if ($this->rtl{
  11663.                         $this->rMargin -= $this->listindent;
  11664.                     else {
  11665.                         $this->lMargin -= $this->listindent;
  11666.                     }
  11667.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  11668.                     break;
  11669.                 }
  11670.                 case 'p'{
  11671.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  11672.                     break;
  11673.                 }
  11674.                 case 'pre'{
  11675.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']true);
  11676.                     $this->premode false;
  11677.                     break;
  11678.                 }
  11679.                 case 'dl'{
  11680.                     --$this->listnum;
  11681.                     if ($this->listnum <= 0{
  11682.                         $this->listnum 0;
  11683.                         $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  11684.                     }
  11685.                     break;
  11686.                 }
  11687.                 case 'dt'{
  11688.                     $this->lispacer '';
  11689.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  11690.                     break;
  11691.                 }
  11692.                 case 'dd'{
  11693.                     $this->lispacer '';
  11694.                     if ($this->rtl{
  11695.                         $this->rMargin -= $this->listindent;
  11696.                     else {
  11697.                         $this->lMargin -= $this->listindent;
  11698.                     }
  11699.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  11700.                     break;
  11701.                 }
  11702.                 case 'ul':
  11703.                 case 'ol'{
  11704.                     --$this->listnum;
  11705.                     $this->lispacer '';
  11706.                     if ($this->rtl{
  11707.                         $this->rMargin -= $this->listindent;
  11708.                     else {
  11709.                         $this->lMargin -= $this->listindent;
  11710.                     }
  11711.                     if ($this->listnum <= 0{
  11712.                         $this->listnum 0;
  11713.                         $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  11714.                     }
  11715.                     $this->lasth $this->FontSize $this->cell_height_ratio;
  11716.                     break;
  11717.                 }
  11718.                 case 'li'{
  11719.                     $this->lispacer '';
  11720.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  11721.                     break;
  11722.                 }
  11723.                 case 'h1'
  11724.                 case 'h2'
  11725.                 case 'h3'
  11726.                 case 'h4'
  11727.                 case 'h5'
  11728.                 case 'h6'{
  11729.                     $this->addHTMLVertSpace(1$cell($parent['fontsize'1.5$this->k$firstorlast$tag['value']true);
  11730.                     break;
  11731.                 }
  11732.                 default {
  11733.                     break;
  11734.                 }
  11735.             }
  11736.             $this->tmprtl false;
  11737.         }
  11738.         
  11739.         /**
  11740.          * Add vertical spaces if needed.
  11741.          * @param int $n number of spaces to add
  11742.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  11743.          * @param string $h The height of the break. By default, the value equals the height of the last printed cell.
  11744.          * @param boolean $firstorlast if true do not print additional empty lines.
  11745.          * @param string $tag HTML tag to which this space will be applied
  11746.          * @param boolean $closing true if this space will be applied to a closing tag, false otherwise
  11747.          * @access protected
  11748.          */
  11749.         protected function addHTMLVertSpace($n$cell=false$h=''$firstorlast=false$tag=''$closing=false{
  11750.             if ($firstorlast{
  11751.                 $this->Ln(0$cell);
  11752.                 $this->htmlvspace 0;
  11753.                 return;
  11754.             }
  11755.             if (isset($this->tagvspaces[$tag][intval($closing)]['n'])) {
  11756.                 $n $this->tagvspaces[$tag][intval($closing)]['n'];
  11757.             }
  11758.             if (isset($this->tagvspaces[$tag][intval($closing)]['h'])) {
  11759.                 $h $this->tagvspaces[$tag][intval($closing)]['h'];
  11760.             }
  11761.             if (is_string($h)) {
  11762.                 $vsize $n $this->lasth;
  11763.             else {
  11764.                 $vsize $n $h;
  11765.             }
  11766.             if ($vsize $this->htmlvspace{
  11767.                 $this->Ln(($vsize $this->htmlvspace)$cell);
  11768.                 $this->htmlvspace $vsize;
  11769.             }
  11770.         }
  11771.         
  11772.         /**
  11773.          * Set the default bullet to be used as LI bullet symbol
  11774.          * @param string $symbol character or string to be used (legal values are: '' = automatic, '!' = auto bullet, '#' = auto numbering, 'disc', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek')
  11775.          * @access public
  11776.          * @since 4.0.028 (2008-09-26)
  11777.          */
  11778.         public function setLIsymbol($symbol='!'{
  11779.             $symbol strtolower($symbol);
  11780.             switch ($symbol{
  11781.                 case '!' :
  11782.                 case '#' :
  11783.                 case 'disc' :
  11784.                 case 'disc' :
  11785.                 case 'circle' :
  11786.                 case 'square' :
  11787.                 case '1':
  11788.                 case 'decimal':
  11789.                 case 'decimal-leading-zero':
  11790.                 case 'i':
  11791.                 case 'lower-roman':
  11792.                 case 'I':
  11793.                 case 'upper-roman':
  11794.                 case 'a':
  11795.                 case 'lower-alpha':
  11796.                 case 'lower-latin':
  11797.                 case 'A':
  11798.                 case 'upper-alpha'
  11799.                 case 'upper-latin':
  11800.                 case 'lower-greek'{
  11801.                     $this->lisymbol $symbol;
  11802.                     break;
  11803.                 }
  11804.                 default {
  11805.                     $this->lisymbol '';
  11806.                 }
  11807.             }
  11808.         }
  11809.         
  11810.         /**
  11811.         * Set the booklet mode for double-sided pages.
  11812.         * @param boolean $booklet true set the booklet mode on, fals eotherwise.
  11813.         * @param float $inner Inner page margin.
  11814.         * @param float $outer Outer page margin.
  11815.         * @access public
  11816.         * @since 4.2.000 (2008-10-29)
  11817.         */
  11818.         public function SetBooklet($booklet=true$inner=-1$outer=-1{
  11819.             $this->booklet $booklet;
  11820.             if ($inner >= 0{
  11821.                 $this->lMargin $inner;
  11822.             }
  11823.             if ($outer >= 0{
  11824.                 $this->rMargin $outer;
  11825.             }
  11826.         }
  11827.         
  11828.         /**
  11829.         * Swap the left and right margins.
  11830.         * @param boolean $reverse if true swap left and right margins.
  11831.         * @access protected
  11832.         * @since 4.2.000 (2008-10-29)
  11833.         */
  11834.         protected function swapMargins($reverse=true{
  11835.             if ($reverse{
  11836.                 // swap left and right margins
  11837.                 $mtemp $this->original_lMargin;
  11838.                 $this->original_lMargin $this->original_rMargin;
  11839.                 $this->original_rMargin $mtemp;
  11840.                 $deltam $this->original_lMargin $this->original_rMargin;
  11841.                 $this->lMargin += $deltam;
  11842.                 $this->rMargin -= $deltam;
  11843.             }
  11844.         }
  11845.         
  11846.         /**
  11847.         * Set the vertical spaces for HTML tags.
  11848.         * The array must have the following structure (example):
  11849.         * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  11850.         * The first array level contains the tag names,
  11851.         * the second level contains 0 for opening tags or 1 for closing tags,
  11852.         * the third level contains the vertical space unit (h) and the number spaces to add (n).
  11853.         * If the h parameter is not specified, default values are used.
  11854.         * @param array $tagvs array of tags and relative vertical spaces.
  11855.         * @access public
  11856.         * @since 4.2.001 (2008-10-30)
  11857.         */
  11858.         public function setHtmlVSpace($tagvs{
  11859.             $this->tagvspaces $tagvs;
  11860.         }
  11861.         
  11862.         /**
  11863.         * Set custom width for list indentation.
  11864.         * @param float $width width of the indentation. Use negative value to disable it.
  11865.         * @access public
  11866.         * @since 4.2.007 (2008-11-12)
  11867.         */
  11868.         public function setListIndentWidth($width{
  11869.             return $this->customlistindent floatval($width);
  11870.         }
  11871.         
  11872.         /**
  11873.         * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  11874.         * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
  11875.         * @access public
  11876.         * @since 4.2.010 (2008-11-14)
  11877.         */
  11878.         public function setOpenCell($isopen{
  11879.             $this->opencell $isopen;
  11880.         }
  11881.         
  11882.         /**
  11883.         * Set the color and font style for HTML links.
  11884.         * @param array $color RGB array of colors
  11885.         * @param string $fontstyle additional font styles to add
  11886.         * @access public
  11887.         * @since 4.4.003 (2008-12-09)
  11888.         */
  11889.         public function setHtmlLinksStyle($color=array(0,0,255)$fontstyle='U'{
  11890.             $this->htmlLinkColorArray $color;
  11891.             $this->htmlLinkFontStyle $fontstyle;
  11892.         }
  11893.                 
  11894.         /**
  11895.         * convert html string containing value and unit of measure to user's units or points.
  11896.         * @param string $htmlval string containing values and unit
  11897.         * @param string $refsize reference value in points
  11898.         * @param string $defaultunit default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  11899.         * @param boolean $point if true returns points, otherwise returns value in user's units
  11900.         * @return float value in user's unit or point if $points=true
  11901.         * @access public
  11902.         * @since 4.4.004 (2008-12-10)
  11903.         */
  11904.         public function getHTMLUnitToUnits($htmlval$refsize=1$defaultunit='px'$points=false{
  11905.             $supportedunits array('%''em''ex''px''in''cm''mm''pc''pt');
  11906.             $retval 0;
  11907.             $value 0;
  11908.             $unit 'px';
  11909.             $k $this->k;
  11910.             if ($points{
  11911.                 $k 1;
  11912.             }
  11913.             if (in_array($defaultunit$supportedunits)) {
  11914.                 $unit $defaultunit;
  11915.             }
  11916.             if (is_numeric($htmlval)) {
  11917.                 $value floatval($htmlval);
  11918.             elseif (preg_match('/([0-9\.]+)/'$htmlval$mnum)) {
  11919.                 $value floatval($mnum[1]);
  11920.                 if (preg_match('/([a-z%]+)/'$htmlval$munit)) {
  11921.                     if (in_array($munit[1]$supportedunits)) {
  11922.                         $unit $munit[1];
  11923.                     }
  11924.                 }
  11925.             }
  11926.             switch ($unit{
  11927.                 // percentage
  11928.                 case '%'{
  11929.                     $retval (($value $refsize100);
  11930.                     break;
  11931.                 }
  11932.                 // relative-size
  11933.                 case 'em'{
  11934.                     $retval ($value $refsize);
  11935.                     break;
  11936.                 }
  11937.                 case 'ex'{
  11938.                     $retval $value ($refsize 2);
  11939.                     break;
  11940.                 }
  11941.                 // absolute-size
  11942.                 case 'in'{
  11943.                     $retval ($value $this->dpi$k;
  11944.                     break;
  11945.                 }
  11946.                 case 'cm'{
  11947.                     $retval ($value 2.54 $this->dpi$k;
  11948.                     break;
  11949.                 }
  11950.                 case 'mm'{
  11951.                     $retval ($value 25.4 $this->dpi$k;
  11952.                     break;
  11953.                 }
  11954.                 case 'pc'{
  11955.                     // one pica is 12 points
  11956.                     $retval ($value 12$k;
  11957.                     break;
  11958.                 }
  11959.                 case 'px':
  11960.                 case 'pt'{
  11961.                     $retval $value $k;
  11962.                     break;
  11963.                 }
  11964.             }
  11965.             return $retval;
  11966.         }
  11967.         
  11968.         /**
  11969.         * Returns the Roman representation of an integer number
  11970.         * @param int number to convert
  11971.         * @return string roman representation of the specified number
  11972.         * @access public
  11973.         * @since 4.4.004 (2008-12-10)
  11974.         */
  11975.         public function intToRoman($number{
  11976.             $roman '';
  11977.             while ($number >= 1000{
  11978.                 $roman .= 'M';
  11979.                 $number -= 1000;
  11980.             }
  11981.             while ($number >= 900{
  11982.                 $roman .= 'CM';
  11983.                 $number -= 900;
  11984.             }
  11985.             while ($number >= 500{
  11986.                 $roman .= 'D';
  11987.                 $number -= 500;
  11988.             }
  11989.             while ($number >= 400{
  11990.                 $roman .= 'CD';
  11991.                 $number -= 400;
  11992.             }
  11993.             while ($number >= 100{
  11994.                 $roman .= 'C';
  11995.                 $number -= 100;
  11996.             }
  11997.             while ($number >= 90){
  11998.             $roman .= 'XC';
  11999.             $number -= 90;
  12000.             }
  12001.             while ($number >= 50{
  12002.                 $roman .= 'L';
  12003.                 $number -= 50;
  12004.             }
  12005.             while ($number >= 40{
  12006.                 $roman .= 'XL';
  12007.                 $number -= 40;
  12008.             }
  12009.             while ($number >= 10{
  12010.             $roman .= 'X';
  12011.             $number -= 10;
  12012.             }
  12013.             while ($number >= 9{
  12014.                 $roman .= 'IX';
  12015.                 $number -= 9;
  12016.             }
  12017.             while ($number >= 5{
  12018.                 $roman .= 'V';
  12019.                 $number -= 5;
  12020.             }
  12021.             while ($number >= 4{
  12022.             $roman .= 'IV';
  12023.             $number -= 4;
  12024.             }
  12025.             while ($number >= 1{
  12026.                 $roman .= 'I';
  12027.                 --$number;
  12028.             }
  12029.             return $roman;
  12030.         }
  12031.         
  12032.         /**
  12033.         * Output an HTML list bullet or ordered item symbol
  12034.         * @param int $listdepth list nesting level
  12035.         * @param string $listtype type of list
  12036.         * @param float $size current font size
  12037.         * @access protected
  12038.         * @since 4.4.004 (2008-12-10)
  12039.         */
  12040.         protected function putHtmlListBullet($listdepth$listtype=''$size=10{
  12041.             $size /= $this->k;
  12042.             $fill '';
  12043.             $color array(000);
  12044.             $width 0;
  12045.             $textitem '';
  12046.             $tmpx $this->x;        
  12047.             $lspace $this->GetStringWidth('  ');
  12048.             if ($listtype == '!'{
  12049.                 // set default list type for unordered list
  12050.                 $deftypes array('disc''circle''square');
  12051.                 $listtype $deftypes[($listdepth 13];
  12052.             elseif ($listtype == '#'{
  12053.                 // set default list type for ordered list
  12054.                 $listtype 'decimal';
  12055.             }
  12056.             switch ($listtype{
  12057.                 // unordered types
  12058.                 case 'none'{
  12059.                     break;
  12060.                 }
  12061.                 case 'disc'{
  12062.                     $fill 'F';
  12063.                 }
  12064.                 case 'circle'{
  12065.                     $fill .= 'D';
  12066.                     $r $size 6;
  12067.                     $lspace += ($r);
  12068.                     if ($this->rtl{
  12069.                         $this->x += $lspace;
  12070.                     else {
  12071.                         $this->x -= $lspace;
  12072.                     }
  12073.                     $this->Circle(($this->x $r)($this->y ($this->lasth 2))$r0360$fillarray('color'=>$color)$color8);
  12074.                     break;
  12075.                 }
  12076.                 case 'square'{
  12077.                     $l $size 3;
  12078.                     $lspace += $l;
  12079.                     if ($this->rtl{
  12080.                         $this->x += $lspace;
  12081.                     else {
  12082.                         $this->x -= $lspace;
  12083.                     }
  12084.                     $this->Rect($this->x($this->y (($this->lasth $l)2))$l$l'F'array()$color);
  12085.                     break;
  12086.                 }
  12087.                 // ordered types
  12088.                 
  12089.                 // $this->listcount[$this->listnum];
  12090.                 // $textitem
  12091.                 case '1':
  12092.                 case 'decimal'{
  12093.                     $textitem $this->listcount[$this->listnum];
  12094.                     break;
  12095.                 }
  12096.                 case 'decimal-leading-zero'{
  12097.                     $textitem sprintf("%02d"$this->listcount[$this->listnum]);
  12098.                     break;
  12099.                 }
  12100.                 case 'i':
  12101.                 case 'lower-roman'{
  12102.                     $textitem strtolower($this->intToRoman($this->listcount[$this->listnum]));
  12103.                     break;
  12104.                 }
  12105.                 case 'I':
  12106.                 case 'upper-roman'{
  12107.                     $textitem $this->intToRoman($this->listcount[$this->listnum]);
  12108.                     break;
  12109.                 }
  12110.                 case 'a':
  12111.                 case 'lower-alpha':
  12112.                 case 'lower-latin'{
  12113.                     $textitem chr(97 $this->listcount[$this->listnum1);
  12114.                     break;
  12115.                 }
  12116.                 case 'A':
  12117.                 case 'upper-alpha'
  12118.                 case 'upper-latin'{
  12119.                     $textitem chr(65 $this->listcount[$this->listnum1);
  12120.                     break;
  12121.                 }
  12122.                 case 'lower-greek'{
  12123.                     $textitem $this->unichr(945 $this->listcount[$this->listnum1);
  12124.                     break;
  12125.                 }
  12126.                 /*
  12127.                 // Types to be implemented (special handling)
  12128.                 case 'hebrew': {
  12129.                     break;
  12130.                 }
  12131.                 case 'armenian': {
  12132.                     break;
  12133.                 }
  12134.                 case 'georgian': {
  12135.                     break;
  12136.                 }
  12137.                 case 'cjk-ideographic': {
  12138.                     break;
  12139.                 }
  12140.                 case 'hiragana': {
  12141.                     break;
  12142.                 }
  12143.                 case 'katakana': {
  12144.                     break;
  12145.                 }
  12146.                 case 'hiragana-iroha': {
  12147.                     break;
  12148.                 }
  12149.                 case 'katakana-iroha': {
  12150.                     break;
  12151.                 }
  12152.                 */
  12153.                 default{
  12154.                     $textitem $this->listcount[$this->listnum];
  12155.                 }
  12156.             }
  12157.             if (!empty($textitem)) {
  12158.                 // print ordered item
  12159.                 if ($this->rtl{
  12160.                     $textitem '.'.$textitem;
  12161.                 else {
  12162.                     $textitem $textitem.'.';
  12163.                 }
  12164.                 $lspace += $this->GetStringWidth($textitem);
  12165.                 if ($this->rtl{
  12166.                     $this->x += $lspace;
  12167.                 else {
  12168.                     $this->x -= $lspace;
  12169.                 }
  12170.                 $this->Write($this->lasth$textitem''false''false0false);
  12171.             }
  12172.             $this->x $tmpx;
  12173.             $this->lispacer '';
  12174.         }
  12175.         
  12176.         /**
  12177.         * Returns current graphic variables as array.
  12178.         * @return array graphic variables
  12179.         * @access protected
  12180.         * @since 4.2.010 (2008-11-14)
  12181.         */
  12182.         protected function getGraphicVars({
  12183.             $grapvars array(
  12184.                 'FontFamily' => $this->FontFamily,
  12185.                 'FontStyle' => $this->FontStyle,
  12186.                 'FontSizePt' => $this->FontSizePt,
  12187.                 'rMargin' => $this->rMargin,
  12188.                 'lMargin' => $this->lMargin,
  12189.                 'cMargin' => $this->cMargin,
  12190.                 'LineWidth' => $this->LineWidth,
  12191.                 'linestyleWidth' => $this->linestyleWidth,
  12192.                 'linestyleCap' => $this->linestyleCap,
  12193.                 'linestyleJoin' => $this->linestyleJoin,
  12194.                 'linestyleDash' => $this->linestyleDash,
  12195.                 'DrawColor' => $this->DrawColor,
  12196.                 'FillColor' => $this->FillColor,
  12197.                 'TextColor' => $this->TextColor,
  12198.                 'ColorFlag' => $this->ColorFlag,
  12199.                 'bgcolor' => $this->bgcolor,
  12200.                 'fgcolor' => $this->fgcolor,
  12201.                 'htmlvspace' => $this->htmlvspace,
  12202.                 'lasth' => $this->lasth
  12203.                 );
  12204.             return $grapvars;
  12205.         }
  12206.         
  12207.         /**
  12208.         * Set graphic variables.
  12209.         * @param $gvars array graphic variables
  12210.         * @access protected
  12211.         * @since 4.2.010 (2008-11-14)
  12212.         */
  12213.         protected function setGraphicVars($gvars{
  12214.             $this->FontFamily $gvars['FontFamily'];
  12215.             $this->FontStyle $gvars['FontStyle'];
  12216.             $this->FontSizePt $gvars['FontSizePt'];
  12217.             $this->rMargin $gvars['rMargin'];
  12218.             $this->lMargin $gvars['lMargin'];
  12219.             $this->cMargin $gvars['cMargin'];
  12220.             $this->LineWidth $gvars['LineWidth'];
  12221.             $this->linestyleWidth $gvars['linestyleWidth'];
  12222.             $this->linestyleCap $gvars['linestyleCap'];
  12223.             $this->linestyleJoin $gvars['linestyleJoin'];
  12224.             $this->linestyleDash $gvars['linestyleDash'];
  12225.             $this->DrawColor $gvars['DrawColor'];
  12226.             $this->FillColor $gvars['FillColor'];
  12227.             $this->TextColor $gvars['TextColor'];
  12228.             $this->ColorFlag $gvars['ColorFlag'];
  12229.             $this->bgcolor $gvars['bgcolor'];
  12230.             $this->fgcolor $gvars['fgcolor'];
  12231.             $this->htmlvspace $gvars['htmlvspace'];
  12232.             //$this->lasth = $gvars['lasth'];
  12233.             $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  12234.             if (!empty($this->FontFamily)) {
  12235.                 $this->SetFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  12236.             }
  12237.         }
  12238.                 
  12239.         /**
  12240.         * Returns a temporary filename for caching object on filesystem.
  12241.         * @param string $prefix prefix to add to filename
  12242.         *  return string filename.
  12243.         * @access protected
  12244.         * @since 4.5.000 (2008-12-31)
  12245.         */
  12246.         protected function getObjFilename($name{
  12247.             return tempnam(K_PATH_CACHE$name.'_');
  12248.         }
  12249.         
  12250.         /**
  12251.         * Writes data to a temporary file on filesystem.
  12252.         * @param string $file file name
  12253.         * @param mixed $data data to write on file
  12254.         * @param boolean $append if true append data, false replace.
  12255.         * @access protected
  12256.         * @since 4.5.000 (2008-12-31)
  12257.         */
  12258.         protected function writeDiskCache($filename$data$append=false{
  12259.             if ($append{
  12260.                 $fmode 'ab+';
  12261.             else {
  12262.                 $fmode 'wb+';
  12263.             }
  12264.             $f @fopen($filename$fmode);
  12265.             if (!$f{
  12266.                 $this->Error('Unable to write cache file: '.$filename);
  12267.             else {
  12268.                 fwrite($f$data);
  12269.                 fclose($f);
  12270.             }
  12271.         }
  12272.         
  12273.         /**
  12274.         * Read data from a temporary file on filesystem.
  12275.         * @param string $file file name
  12276.         * @return mixed retrieved data
  12277.         * @access protected
  12278.         * @since 4.5.000 (2008-12-31)
  12279.         */
  12280.         protected function readDiskCache($filename{
  12281.             return file_get_contents($filename);
  12282.         }
  12283.         
  12284.         /**
  12285.         * Set buffer content (always append data).
  12286.         * @param string $data data
  12287.         * @access protected
  12288.         * @since 4.5.000 (2009-01-02)
  12289.         */
  12290.         protected function setBuffer($data{
  12291.             if ($this->diskcache{
  12292.                 if (!isset($this->bufferOR empty($this->buffer)) {
  12293.                     $this->buffer $this->getObjFilename('buffer');
  12294.                 }
  12295.                 $this->writeDiskCache($this->buffer$datatrue);
  12296.             else {
  12297.                 $this->buffer .= $data;
  12298.             }
  12299.             $this->bufferlen += strlen($data);
  12300.         }
  12301.         
  12302.         /**
  12303.         * Get buffer content.
  12304.         * @return string buffer content
  12305.         * @access protected
  12306.         * @since 4.5.000 (2009-01-02)
  12307.         */
  12308.         protected function getBuffer({
  12309.             if ($this->diskcache{
  12310.                 return $this->readDiskCache($this->buffer)
  12311.             else {
  12312.                 return $this->buffer;
  12313.             }
  12314.         }
  12315.         
  12316.         /**
  12317.         * Set page buffer content.
  12318.         * @param int $page page number
  12319.         * @param string $data page data
  12320.         * @param boolean $append if true append data, false replace.
  12321.         * @access protected
  12322.         * @since 4.5.000 (2008-12-31)
  12323.         */
  12324.         protected function setPageBuffer($page$data$append=false{
  12325.             if ($this->diskcache{
  12326.                 if (!isset($this->pages[$page])) {
  12327.                     $this->pages[$page$this->getObjFilename('page'.$page);
  12328.                 }
  12329.                 $this->writeDiskCache($this->pages[$page]$data$append);
  12330.             else {
  12331.                 if ($append{
  12332.                     $this->pages[$page.= $data;
  12333.                 else {
  12334.                     $this->pages[$page$data;
  12335.                 }
  12336.             }
  12337.             if ($append AND isset($this->pagelen[$page])){
  12338.                 $this->pagelen[$page+= strlen($data);
  12339.             else {
  12340.                 $this->pagelen[$pagestrlen($data);
  12341.             }
  12342.         }
  12343.         
  12344.         /**
  12345.         * Get page buffer content.
  12346.         * @param int $page page number
  12347.         * @return string page buffer content or false in case of error
  12348.         * @access protected
  12349.         * @since 4.5.000 (2008-12-31)
  12350.         */
  12351.         protected function getPageBuffer($page{
  12352.             if ($this->diskcache{
  12353.                 return $this->readDiskCache($this->pages[$page])
  12354.             elseif (isset($this->pages[$page])) {
  12355.                 return $this->pages[$page];
  12356.             }
  12357.             return false;
  12358.         }
  12359.         
  12360.         /**
  12361.         * Set image buffer content.
  12362.         * @param string $image image key
  12363.         * @param array $data image data
  12364.         * @access protected
  12365.         * @since 4.5.000 (2008-12-31)
  12366.         */
  12367.         protected function setImageBuffer($image$data{
  12368.             if ($this->diskcache{
  12369.                 if (!isset($this->images[$image])) {
  12370.                     $this->images[$image$this->getObjFilename('image'.$image);
  12371.                 }
  12372.                 $this->writeDiskCache($this->images[$image]serialize($data));
  12373.             else {
  12374.                 $this->images[$image$data;
  12375.             }
  12376.             if (!in_array($image$this->imagekeys)) {
  12377.                 $this->imagekeys[$image;
  12378.             }
  12379.             ++$this->numimages;
  12380.         }
  12381.         
  12382.         /**
  12383.         * Set image buffer content.
  12384.         * @param string $image image key
  12385.         * @param string $key image sub-key
  12386.         * @param array $data image data
  12387.         * @access protected
  12388.         * @since 4.5.000 (2008-12-31)
  12389.         */
  12390.         protected function setImageSubBuffer($image$key$data{
  12391.             if (!isset($this->images[$image])) {
  12392.                 $this->setImageBuffer($imagearray());
  12393.             }
  12394.             if ($this->diskcache{
  12395.                 $tmpimg $this->getImageBuffer($image);
  12396.                 $tmpimg[$key$data;
  12397.                 $this->writeDiskCache($this->images[$image]serialize($tmpimg));
  12398.             else {
  12399.                 $this->images[$image][$key$data;
  12400.             }
  12401.         }
  12402.         
  12403.         /**
  12404.         * Get page buffer content.
  12405.         * @param string $image image key
  12406.         * @return string image buffer content or false in case of error
  12407.         * @access protected
  12408.         * @since 4.5.000 (2008-12-31)
  12409.         */
  12410.         protected function getImageBuffer($image{
  12411.             if ($this->diskcache AND isset($this->images[$image])) {
  12412.                 return unserialize($this->readDiskCache($this->images[$image]))
  12413.             elseif (isset($this->images[$image])) {
  12414.                 return $this->images[$image];
  12415.             }
  12416.             return false;
  12417.         }
  12418.         
  12419.         /**
  12420.         * Set font buffer content.
  12421.         * @param string $font font key
  12422.         * @param array $data font data
  12423.         * @access protected
  12424.         * @since 4.5.000 (2009-01-02)
  12425.         */
  12426.         protected function setFontBuffer($font$data{
  12427.             if ($this->diskcache{
  12428.                 if (!isset($this->fonts[$font])) {
  12429.                     $this->fonts[$font$this->getObjFilename('font');
  12430.                 }
  12431.                 $this->writeDiskCache($this->fonts[$font]serialize($data));
  12432.             else {
  12433.                 $this->fonts[$font$data;
  12434.             }
  12435.             if (!in_array($font$this->fontkeys)) {
  12436.                 $this->fontkeys[$font;
  12437.             }
  12438.         }
  12439.         
  12440.         /**
  12441.         * Set font buffer content.
  12442.         * @param string $font font key
  12443.         * @param string $key font sub-key
  12444.         * @param array $data font data
  12445.         * @access protected
  12446.         * @since 4.5.000 (2009-01-02)
  12447.         */
  12448.         protected function setFontSubBuffer($font$key$data{
  12449.             if (!isset($this->fonts[$font])) {
  12450.                 $this->setFontBuffer($fontarray());
  12451.             }
  12452.             if ($this->diskcache{
  12453.                 $tmpfont $this->getFontBuffer($font);
  12454.                 $tmpfont[$key$data;
  12455.                 $this->writeDiskCache($this->fonts[$font]serialize($tmpfont));
  12456.             else {
  12457.                 $this->fonts[$font][$key$data;
  12458.             }
  12459.         }
  12460.         
  12461.         /**
  12462.         * Get font buffer content.
  12463.         * @param string $font font key
  12464.         * @return string font buffer content or false in case of error
  12465.         * @access protected
  12466.         * @since 4.5.000 (2009-01-02)
  12467.         */
  12468.         protected function getFontBuffer($font{
  12469.             if ($this->diskcache AND isset($this->fonts[$font])) {
  12470.                 return unserialize($this->readDiskCache($this->fonts[$font]))
  12471.             elseif (isset($this->fonts[$font])) {
  12472.                 return $this->fonts[$font];
  12473.             }
  12474.             return false;
  12475.         }
  12476.         
  12477.         /**
  12478.         * Move a page to a previous position.
  12479.         * Use this method just before Output().
  12480.         * @param int $frompage number of the source page
  12481.         * @param int $topage number of the destination page (must be less than $frompage)
  12482.         * @return true in case of success, false in case of error.
  12483.         * @access public
  12484.         * @since 4.5.000 (2009-01-02)
  12485.         */
  12486.         public function movePage($frompage$topage{
  12487.             if (($frompage $this->numpagesOR ($frompage <= $topage)) {
  12488.                 return false;
  12489.             }
  12490.             if ($frompage == $this->page{
  12491.                 // close the page before moving it
  12492.                 $this->endPage();
  12493.             }
  12494.             // move all page-related states
  12495.             $tmppage $this->pages[$frompage];
  12496.             $tmppagedim $this->pagedim[$frompage];
  12497.             $tmppagelen $this->pagelen[$frompage];
  12498.             $tmpintmrk $this->intmrk[$frompage];
  12499.             if (isset($this->footerpos[$frompage])) {
  12500.                 $tmpfooterpos $this->footerpos[$frompage];
  12501.             }
  12502.             if (isset($this->footerlen[$frompage])) {
  12503.                 $tmpfooterlen $this->footerlen[$frompage];
  12504.             }
  12505.             if (isset($this->transfmrk[$frompage])) {
  12506.                 $tmptransfmrk $this->transfmrk[$frompage];
  12507.             }
  12508.             if (isset($this->PageAnnots[$frompage])) {
  12509.                 $tmpannots $this->PageAnnots[$frompage];
  12510.             }
  12511.             if (isset($this->newpagegroup[$frompage])) {
  12512.                 $tmpnewpagegroup $this->newpagegroup[$frompage];
  12513.             }
  12514.             for ($i $frompage$i $topage$i--{
  12515.                 // shift pages down
  12516.                 $this->pages[$i$this->pages[($i 1)];
  12517.                 $this->pagedim[$i$this->pagedim[($i 1)];
  12518.                 $this->pagelen[$i$this->pagelen[($i 1)];
  12519.                 $this->intmrk[$i$this->intmrk[($i 1)];
  12520.                 if (isset($this->footerpos[($i 1)])) {
  12521.                     $this->footerpos[$i$this->footerpos[($i 1)];
  12522.                 elseif (isset($this->footerpos[$i])) {
  12523.                     unset($this->footerpos[$i]);
  12524.                 }
  12525.                 if (isset($this->footerlen[($i 1)])) {
  12526.                     $this->footerlen[$i$this->footerlen[($i 1)];
  12527.                 elseif (isset($this->footerlen[$i])) {
  12528.                     unset($this->footerlen[$i]);
  12529.                 }
  12530.                 if (isset($this->transfmrk[($i 1)])) {
  12531.                     $this->transfmrk[$i$this->transfmrk[($i 1)];
  12532.                 elseif (isset($this->transfmrk[$i])) {
  12533.                     unset($this->transfmrk[$i]);
  12534.                 }
  12535.                 if (isset($this->PageAnnots[($i 1)])) {
  12536.                     $this->PageAnnots[$i$this->PageAnnots[($i 1)];
  12537.                 elseif (isset($this->PageAnnots[$i])) {
  12538.                     unset($this->PageAnnots[$i]);
  12539.                 }
  12540.                 if (isset($this->newpagegroup[($i 1)])) {
  12541.                     $this->newpagegroup[$i$this->newpagegroup[($i 1)];
  12542.                 elseif (isset($this->newpagegroup[$i])) {
  12543.                     unset($this->newpagegroup[$i]);
  12544.                 }
  12545.             }
  12546.             $this->pages[$topage$tmppage;
  12547.             $this->pagedim[$topage$tmppagedim;
  12548.             $this->pagelen[$topage$tmppagelen;
  12549.             $this->intmrk[$topage$tmpintmrk;
  12550.             if (isset($tmpfooterpos)) {
  12551.                 $this->footerpos[$topage$tmpfooterpos;
  12552.             elseif (isset($this->footerpos[$topage])) {
  12553.                 unset($this->footerpos[$topage]);
  12554.             }
  12555.             if (isset($tmpfooterlen)) {
  12556.                 $this->footerlen[$topage$tmpfooterlen;
  12557.             elseif (isset($this->footerlen[$topage])) {
  12558.                 unset($this->footerlen[$topage]);
  12559.             }
  12560.             if (isset($tmptransfmrk)) {
  12561.                 $this->transfmrk[$topage$tmptransfmrk;
  12562.             elseif (isset($this->transfmrk[$topage])) {
  12563.                 unset($this->transfmrk[$topage]);
  12564.             }
  12565.             if (isset($tmpannots)) {
  12566.                 $this->PageAnnots[$topage$tmpannots;
  12567.             elseif (isset($this->PageAnnots[$topage])) {
  12568.                 unset($this->PageAnnots[$topage]);
  12569.             }
  12570.             if (isset($tmpnewpagegroup)) {
  12571.                 $this->newpagegroup[$topage$tmpnewpagegroup;
  12572.             elseif (isset($this->newpagegroup[$topage])) {
  12573.                 unset($this->newpagegroup[$topage]);
  12574.             }
  12575.             // adjust outlines
  12576.             $tmpoutlines $this->outlines;
  12577.             foreach ($tmpoutlines as $key => $outline{
  12578.                 if (($outline['p'>= $topageAND ($outline['p'$frompage)) {
  12579.                     $this->outlines[$key]['p'$outline['p'1;
  12580.                 elseif ($outline['p'== $frompage{
  12581.                     $this->outlines[$key]['p'$topage;
  12582.                 }
  12583.             }
  12584.             // adjust links
  12585.             $tmplinks $this->links;
  12586.             foreach ($tmplinks as $key => $link{
  12587.                 if (($link[0>= $topageAND ($link[0$frompage)) {
  12588.                     $this->links[$key][0$link[01;
  12589.                 elseif ($link[0== $frompage{
  12590.                     $this->links[$key][0$topage;
  12591.                 }
  12592.             }
  12593.             // adjust javascript
  12594.             $tmpjavascript $this->javascript;
  12595.             global $jfrompage$jtopage;
  12596.             $jfrompage $frompage
  12597.             $jtopage $topage;
  12598.             $this->javascript preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/'
  12599.                 create_function('$matches''global $jfrompage, $jtopage;
  12600.                 $pagenum = intval($matches[3]) + 1;
  12601.                 if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  12602.                     $newpage = ($pagenum + 1);
  12603.                 } elseif ($pagenum == $jfrompage) {
  12604.                     $newpage = $jtopage;
  12605.                 } else {
  12606.                     $newpage = $pagenum;
  12607.                 }
  12608.                 --$newpage;
  12609.                 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";')$tmpjavascript);
  12610.             // return to last page
  12611.             $this->lastPage(true);
  12612.             return true;
  12613.         }
  12614.         
  12615.         /*
  12616.         * Output a Table of Content Index (TOC).
  12617.         * You can override this method to achieve different styles.
  12618.         * @param int $page page number where this TOC should be inserted (leave empty for current page).
  12619.         * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
  12620.         * @param string $filler string used to fill the space between text and page number.
  12621.         * @access public
  12622.         * @author Nicola Asuni
  12623.         * @since 4.5.000 (2009-01-02)
  12624.         */
  12625.         public function addTOC($page=''$numbersfont='courier'$filler='.'{
  12626.             $fontsize $this->FontSizePt;
  12627.             $fontfamily $this->FontFamily;
  12628.             $fontstyle $this->FontStyle;
  12629.             $w $this->w $this->lMargin $this->rMargin;
  12630.             $spacer $this->GetStringWidth(' '4;
  12631.             $page_first $this->getPage();
  12632.             $lmargin $this->lMargin;
  12633.             $rmargin $this->rMargin;
  12634.             $x_start $this->GetX();
  12635.             if (empty($filler)) {
  12636.                 $filler ' ';
  12637.             }
  12638.             if (empty($page)) {
  12639.                 $gap ' ';
  12640.             else {
  12641.                 $gap '';
  12642.             }
  12643.             foreach ($this->outlines as $key => $outline{
  12644.                 if ($this->rtl{
  12645.                     $aligntext 'R';
  12646.                     $alignnum 'L';
  12647.                 else {
  12648.                     $aligntext 'L';
  12649.                     $alignnum 'R';
  12650.                 }
  12651.                 if ($outline['l'== 0{
  12652.                     $this->SetFont($fontfamily$fontstyle.'B'$fontsize);
  12653.                 else {
  12654.                     $this->SetFont($fontfamily$fontstyle$fontsize $outline['l']);
  12655.                 }
  12656.                 $indent ($spacer $outline['l']);
  12657.                 if ($this->rtl{
  12658.                     $this->rMargin += $indent;
  12659.                     $this->x -= $indent;
  12660.                 else {
  12661.                     $this->lMargin += $indent;
  12662.                     $this->x += $indent;
  12663.                 }
  12664.                 $link $this->AddLink();
  12665.                 $this->SetLink($link0$outline['p']);
  12666.                 // write the text
  12667.                 $this->Write(0$outline['t']$link0$aligntextfalse0falsefalse0);
  12668.                 $this->SetFont($numbersfont$fontstyle$fontsize);
  12669.                 if (empty($page)) {
  12670.                     $pagenum $outline['p'];
  12671.                 else {
  12672.                     // placemark to be replaced with the correct number
  12673.                     $pagenum '{#'.($outline['p']).'}';
  12674.                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  12675.                         $pagenum '{'.$pagenum.'}';
  12676.                     }
  12677.                 }
  12678.                 $numwidth $this->GetStringWidth($pagenum);
  12679.                 if ($this->rtl{
  12680.                     $tw $this->x $this->lMargin;
  12681.                 else {
  12682.                     $tw $this->w $this->rMargin $this->x;
  12683.                 }
  12684.                 $fw $tw $numwidth $this->GetStringWidth(' ');
  12685.                 $numfills floor($fw $this->GetStringWidth($filler));
  12686.                 $rowfill str_repeat($filler$numfills);
  12687.                 if ($this->rtl{
  12688.                     $pagenum $pagenum.$gap.$rowfill.' ';
  12689.                 else {
  12690.                     $pagenum ' '.$rowfill.$gap.$pagenum;
  12691.                 }
  12692.                 // write the number
  12693.                 //$this->SetX($x_start);
  12694.                 $this->Cell($tw0$pagenum01$alignnum0$link0);
  12695.                 $this->SetX($x_start);
  12696.                 $this->lMargin $lmargin;
  12697.                 $this->rMargin $rmargin;
  12698.             }
  12699.             $page_last $this->getPage();
  12700.             $numpages $page_last $page_first 1;
  12701.             if (!empty($page)) {
  12702.                 for($p $page_first$p <= $page_last++$p{
  12703.                     // get page data
  12704.                     $temppage $this->getPageBuffer($p);
  12705.                     for($n 1$n <= $this->numpages++$n{
  12706.                         // update page numbers
  12707.                         $k '{#'.$n.'}';
  12708.                         $ku '{'.$k.'}';
  12709.                         $alias_a $this->_escape($k);
  12710.                         $alias_au $this->_escape('{'.$k.'}');
  12711.                         if ($this->isunicode{
  12712.                             $alias_b $this->_escape($this->UTF8ToLatin1($k));
  12713.                             $alias_bu $this->_escape($this->UTF8ToLatin1($ku));
  12714.                             $alias_c $this->_escape($this->utf8StrRev($kfalse$this->tmprtl));
  12715.                             $alias_cu $this->_escape($this->utf8StrRev($kufalse$this->tmprtl));
  12716.                         }
  12717.                         if ($n >= $page{
  12718.                             $np $n $numpages;
  12719.                         else {
  12720.                             $np $n;
  12721.                         }
  12722.                         $ns $this->formatTOCPageNumber($np);
  12723.                         $nu $ns;
  12724.                         $sdiff strlen($kstrlen($ns1;
  12725.                         $sdiffu strlen($kustrlen($ns1;
  12726.                         $sfill str_repeat($filler$sdiff);
  12727.                         $sfillu str_repeat($filler$sdiffu);
  12728.                         if ($this->rtl{
  12729.                             $ns $ns.' '.$sfill;
  12730.                             $nu $nu.' '.$sfillu;
  12731.                         else {
  12732.                             $ns $sfill.' '.$ns;
  12733.                             $nu $sfillu.' '.$nu;
  12734.                         }
  12735.                         $nu $this->UTF8ToUTF16BE($nufalse);
  12736.                         $temppage str_replace($alias_au$nu$temppage);
  12737.                         if ($this->isunicode{
  12738.                             $temppage str_replace($alias_bu$nu$temppage);
  12739.                             $temppage str_replace($alias_cu$nu$temppage);
  12740.                             $temppage str_replace($alias_b$ns$temppage);
  12741.                             $temppage str_replace($alias_c$ns$temppage);
  12742.                         }
  12743.                         $temppage str_replace($alias_a$ns$temppage);
  12744.                     }
  12745.                     // save changes
  12746.                     $this->setPageBuffer($p$temppage);
  12747.                 }
  12748.                 // move pages
  12749.                 for ($i 0$i $numpages++$i{
  12750.                     $this->movePage($page_last$page);
  12751.                 }
  12752.             }
  12753.             $this->SetFont($fontfamily$fontstyle$fontsize);
  12754.         }
  12755.     // END OF TCPDF CLASS
  12756. }
  12757. //============================================================+
  12758. // END OF FILE
  12759. //============================================================+
  12760. ?>

Documentation generated on Tue, 17 Mar 2009 08:29:57 +0100 by phpDocumentor 1.4.1